Passed
Push — main ( a38817...2056a2 )
by Michael
03:05
created

AutoBinder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A performAutoBinding() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\AutoBinder\Core;
6
7
use MichaelRubel\AutoBinder\Traits\AutoBinds;
8
use Symfony\Component\Finder\SplFileInfo;
9
10
class AutoBinder implements AutoBinderContract
11
{
12
    use AutoBinds;
13
14
    /**
15
     * @return void
16
     */
17 2
    public function __construct()
18
    {
19 2
        $this->performAutoBinding();
20
    }
21
22
    /**
23
     * @return void
24
     */
25 2
    private function performAutoBinding(): void
26
    {
27 2
        collect(config('auto-binder.scan_folders', self::DEFAULT_SCAN_FOLDERS))
28 2
            ->pipe(function ($folders) {
29 2
                $this->prepareNamespace();
30
31 2
                return $folders;
32
            })
33 2
            ->each(fn (string $folder) => $this->getFolderFiles($folder)
34 2
                ->each(function (SplFileInfo $file) use ($folder) {
35 2
                    $relativePath             = $file->getRelativePathname();
36 2
                    $filenameWithoutExtension = $file->getFilenameWithoutExtension();
37 2
                    $filenameWithRelativePath = $this->cleanupFilename($relativePath);
38
39 2
                    $interface      = $this->getInterface($folder, $filenameWithoutExtension);
40 2
                    $implementation = $this->getImplementation($folder, $filenameWithRelativePath);
41
42 2
                    $this->bind($interface, $implementation);
43
                })
44
            );
45
    }
46
}
47