CollectionMacroServiceProvider   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 1
1
<?php
2
3
namespace Spatie\CollectionMacros;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\ServiceProvider;
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 Sebastian De Deyne
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
                Collection::macro(Str::camel($macro), app($class)());
23
            });
24
    }
25
}
26