CollectionMacroServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 23 2
1
<?php
2
3
namespace Spatie\CollectionMacros;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Support\Str;
8
9
class CollectionMacroServiceProvider extends ServiceProvider
10
{
11
    public function register()
12
    {
13
        Collection::make(glob(__DIR__.'/Macros/*.php'))
14
            ->mapWithKeys(function ($path) {
15
                return [$path => pathinfo($path, PATHINFO_FILENAME)];
16
            })
17
            ->reject(function ($macro) {
18
                return Collection::hasMacro($macro);
19
            })
20
            ->each(function ($macro, $path) {
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
                $class = 'Spatie\\CollectionMacros\\Macros\\'.$macro;
22
23
                $macro = Str::camel($macro);
24
25
                if($macro === 'tryCatch') {
26
                    $macro = 'try';
27
                }
28
29
                Collection::macro($macro, app($class)());
30
            });
31
32
33
    }
34
}
35