CollectDependenciesCommand::execute()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 24
cp 0
rs 8.8017
c 0
b 0
f 0
cc 6
nc 9
nop 1
crap 42
1
<?php
2
/**
3
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\commands;
12
13
use hiqdev\assetpackagist\models\AssetPackage;
14
use Yii;
15
use yii\helpers\Console;
16
17
/**
18
 * Class CollectDependenciesCommand collects dependencies for a certain package
19
 * and publishes tasks to update them.
20
 */
21
class CollectDependenciesCommand extends AbstractPackageCommand
22
{
23
    public function execute($queue)
24
    {
25
        $this->beforeRun();
26
27
        $package = $this->package;
28
        $requires = [];
29
30
        foreach ($package->getReleases() as $release) {
31
            if (!isset($release['require'])) {
32
                continue;
33
            }
34
35
            foreach ($release['require'] as $name => $version) {
36
                $requires[$name] = true;
37
            }
38
        }
39
40
        foreach (array_keys($requires) as $name) {
41
            $assetPackage = AssetPackage::fromFullName($name);
42
43
            if ($this->packageRepository->exists($assetPackage)) {
44
                Yii::trace(Console::renderColoredString('Package %N' . $assetPackage->getFullName() . "%n already exists. Skipping.\n"), __CLASS__);
0 ignored issues
show
Deprecated Code introduced by
The method yii\BaseYii::trace() has been deprecated with message: since 2.0.14. Use [[debug()]] instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
                continue;
46
            }
47
48
            $queue->push(Yii::createObject(PackageUpdateCommand::class, [$assetPackage]));
49
            Yii::trace(Console::renderColoredString('Created update command for %Y' . $assetPackage->getFullName() . "%n package\n"), __CLASS__);
0 ignored issues
show
Deprecated Code introduced by
The method yii\BaseYii::trace() has been deprecated with message: since 2.0.14. Use [[debug()]] instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50
        }
51
52
        $this->afterRun();
53
    }
54
}
55