Completed
Push — master ( 39c07f...aa04c1 )
by Jitendra
11s
created

Composer::createProject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ahc\Phint\Util;
4
5
class Composer extends Executable
6
{
7
    /** @var array Content of composer.json decoded */
8
    protected $config = [];
9
10
    /** @var string The binary executable */
11
    protected $binary = 'composer';
12
13
    public function createProject($project, $using)
14
    {
15
        $this->runCommand(sprintf('create-project %s %s', $using, $project));
16
17
        return $this;
18
    }
19
20
    public function install()
21
    {
22
        $this->runCommand('install --prefer-dist --optimize-autoloader --no-suggest');
23
24
        return $this;
25
    }
26
27
    public function update()
28
    {
29
        $this->runCommand('update --prefer-dist --optimize-autoloader --no-suggest');
30
31
        return $this;
32
    }
33
34
    public function dumpAutoload()
35
    {
36
        $this->runCommand('dump-autoload --optimize');
37
38
        return $this;
39
    }
40
41
    public function config(string $key, $default = null)
42
    {
43
        if (!$this->config) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->config of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
44
            $this->config = (new Path)->readAsJson($this->workDir . '/composer.json');
45
        }
46
47
        $temp = $this->config;
48
        foreach (\explode('.', $key) as $part) {
49
            if (\is_array($temp) && \array_key_exists($part, $temp)) {
50
                $temp = $temp[$part];
51
            } else {
52
                return $default;
53
            }
54
        }
55
56
        return $temp;
57
    }
58
}
59