ProxyRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 4
1
<?php
2
3
/*
4
 * This file is part of the phpdish/plugin-installer package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PHPDish\PluginInstaller;
13
14
use Composer\Config;
15
use Composer\IO\IOInterface;
16
use Composer\Package\Loader\ArrayLoader;
17
use Composer\Repository\ArrayRepository;
18
use Composer\Repository\PathRepository;
19
use Symfony\Component\Finder\Finder;
20
21
class ProxyRepository extends ArrayRepository
22
{
23
    /**
24
     * @var ArrayLoader
25
     */
26
    protected $loader;
27
28
    protected $dir;
29
30
    protected $depth;
31
32
    protected $io;
33
34
    protected $config;
35
36
    public function __construct($dir, $depth, IOInterface $io, Config $config)
37
    {
38
        $this->dir = $dir;
39
        $this->depth = $depth;
40
        $this->io = $io;
41
        $this->config = $config;
42
        parent::__construct();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function initialize()
49
    {
50
        parent::initialize();
51
52
        $foundFiles = (new Finder())->in($this->dir)->depth("<={$this->depth}")->name('composer.json')
53
            ->contains('/"type"\s*:\s*"phpdish-plugin"/');
54
55
        foreach ($foundFiles as $file) {
56
            $pathRepository = new PathRepository([
57
                'type' => 'path',
58
                'url' => $file->getPath(),
59
            ], $this->io, $this->config);
60
61
            foreach ($pathRepository->getPackages() as $package) {
62
                $reflection = new \ReflectionObject($package);
63
                $property = $reflection->getProperty('repository');
64
                $property->setAccessible(true);
65
                $property->setValue($package, $this);
66
                $this->addPackage($package);
67
            }
68
            unset($pathRepository);
69
            $pathRepository = null;
0 ignored issues
show
Unused Code introduced by
$pathRepository is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
        }
71
    }
72
}