Completed
Push — master ( 7381e1...0d723c )
by Korvin
02:16
created

LegacyDriver::all()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace Buttress\Concrete\Service\Package\Driver;
4
5
use Buttress\Concrete\Client\Connection\Connection;
6
use Buttress\Concrete\Service\Package\PackageItem;
7
use Buttress\Concrete\Service\Result;
8
use League\CLImate\CLImate;
9
use Package;
10
11
class LegacyDriver implements Driver
12
{
13
14
    /** @var \Buttress\Concrete\Client\Connection\Connection */
15
    private $connection;
16
17
    /** @var \Buttress\Concrete\Service\Package\PackageItemFactory */
18
    private $factory;
19
20
    public function __construct(Connection $connection, PackageItemFactory $factory)
21
    {
22
        $this->connection = $connection;
23
        $this->factory = $factory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $factory of type object<Buttress\Concrete...ver\PackageItemFactory> is incompatible with the declared type object<Buttress\Concrete...age\PackageItemFactory> of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
    }
25
26
    /**
27
     * @param \Buttress\Concrete\Service\Package\PackageItem $package
28
     * @return Package|null
29
     */
30
    private function getPackage(PackageItem $package)
31
    {
32
        $package = Loader::package($package->getHandle());
33
        return is_object($package) ? $package : null;
34
    }
35
36
    /**
37
     * Install a package
38
     *
39
     * @param \Buttress\Concrete\Service\Package\PackageItem $item
40
     * @return \Buttress\Concrete\Service\Result
41
     */
42
    public function install(PackageItem $item)
43
    {
44
        if (!$this->connection->isConnected()) {
45
            return new Result(false, 'Not connected to concrete5 site.');
0 ignored issues
show
Documentation introduced by
'Not connected to concrete5 site.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        }
47
48
        if (!$package = $this->getPackage($item)) {
49
            return new Result(false, 'Invalid package handle.');
0 ignored issues
show
Documentation introduced by
'Invalid package handle.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        }
51
52
        if ($package->showInstallOptionsScreen()) {
53
            return new Result(false, 'Install options are not currently supported. Please install through the dashboard.');
0 ignored issues
show
Documentation introduced by
'Install options are not...through the dashboard.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
        }
55
56
        $tests = $this->test($package);
57
        if (!$tests->success()) {
58
            return $tests;
59
        }
60
61
        try {
62
            $package->install([]);
63
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Buttress\Concrete\Service\Package\Driver\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
64
            return new Result(false, [$e->getMessage()]);
65
        }
66
67
        return new Result();
68
    }
69
70
    /**
71
     * Uninstall a package
72
     *
73
     * @param PackageItem $item
74
     * @return \Buttress\Concrete\Service\Result
75
     */
76
    public function uninstall(PackageItem $item)
77
    {
78
        if (!$this->connection->isConnected()) {
79
            return new Result(false, 'Not connected to concrete5 site.');
0 ignored issues
show
Documentation introduced by
'Not connected to concrete5 site.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
        }
81
82
        if (!$package = $this->getPackage($item)) {
83
            return new Result(false, 'Invalid package handle.');
0 ignored issues
show
Documentation introduced by
'Invalid package handle.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
        }
85
86
        try {
87
            $package->uninstall();
88
        } catch (\Exception $e) {
89
            return new Result(false, [$e->getMessage()]);
90
        }
91
92
        return new Result();
93
    }
94
95
    /**
96
     * Test a package for install
97
     *
98
     * @param PackageItem $package
99
     * @return \Buttress\Concrete\Service\Result
100
     */
101
    public function test(PackageItem $package)
102
    {
103
        if (!$this->connection->isConnected()) {
104
            return new Result(false, 'Not connected to concrete5 site.');
0 ignored issues
show
Documentation introduced by
'Not connected to concrete5 site.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
105
        }
106
107
        $package = $this->getPackage($package);
108
        $errors = [];
109
110
        if (is_array($tests = Package::testForInstall($package, false))) {
111
            $errors = Package::mapError($tests);
112
        }
113
114
        return new Result((bool) $errors, $errors);
115
    }
116
117
    /**
118
     * Show information about a package
119
     *
120
     * @param PackageItem $package
121
     * @return \Buttress\Concrete\Service\Result
122
     */
123 View Code Duplication
    public function show(PackageItem $package, CLImate $cli)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125
        if (!$this->connection->isConnected()) {
126
            return new Result(false, 'Not connected to concrete5 site.');
0 ignored issues
show
Documentation introduced by
'Not connected to concrete5 site.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
        }
128
129
        $cli->flank($package->getHandle());
130
        $cli->out($package->isInstalled() ? 'Installed Version ' : 'Not Installed: ');
131
        $cli->bold()->inline($package->getVersion());
132
    }
133
134
    /**
135
     * Get a list of package item objects
136
     * @return PackageItem[]
137
     */
138
    public function all()
139
    {
140
        if (!$this->connection->isConnected()) {
141
            return new Result(false, 'Not connected to concrete5 site.');
0 ignored issues
show
Documentation introduced by
'Not connected to concrete5 site.' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
        }
143
144
        $packages = Package::getAvailablePackages(false);
145
146
        foreach ($packages as $package) {
147
            yield $this->factory->fromLegacy($package);
148
        }
149
    }
150
}
151