Passed
Push — master ( 8a6050...5a6ead )
by Andrii
11:18
created

Composer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace hidev\components;
4
5
class Composer
6
{
7
    public function __construct(string $dir)
8
    {
9
        $this->dir = ($dir === getcwd() ? '' : $dir);
0 ignored issues
show
Bug Best Practice introduced by
The property dir does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
10
    }
11
12
    public function autoload()
13
    {
14
        $path =  $this->getPath('vendor/autoload.php');
15
        if (!file_exists($path)) {
16
            $this->run('update');
17
        }
18
        require $path;
19
    }
20
21
    public function dump()
22
    {
23
        $this->run('dump-autoload');
24
    }
25
26
    public function run(string $command, array $args = [])
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

26
    public function run(string $command, /** @scrutinizer ignore-unused */ array $args = [])

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

Loading history...
27
    {
28
        sys::passthru("{$this->getCmd()} $command");
29
    }
30
31
    public function getCmd(): string
32
    {
33
        return 'composer' . ($this->dir ? " -d $dir" : '');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dir seems to be never defined.
Loading history...
34
    }
35
36
    public function getPath(string $file): string
37
    {
38
        if (strncmp($file, '/', 1) === 0) {
39
            return $file;
40
        }
41
42
        return $this->dir ? $this->dir . DIRECTORY_SEPARATOR . $file : $file;
43
    }
44
}
45