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

AutoBinder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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