Completed
Push — master ( eb0e60...e48222 )
by Dmitry
02:26
created

PackageUpdateCommand::run()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 8.7972
c 1
b 0
f 0
cc 4
eloc 14
nc 5
nop 0
1
<?php
2
3
namespace hiqdev\assetpackagist\commands;
4
5
use Yii;
6
7
/**
8
 * Class PackageUpdateCommand runs package update command and creates tasks to
9
 * fetch its dependencies.
10
 *
11
 * @package hiqdev\assetpackagist\commands
12
 */
13
class PackageUpdateCommand extends AbstractPackageCommand
14
{
15
    public function run()
16
    {
17
        $this->beforeRun();
18
19
        if (!$this->package->canBeUpdated()) {
20
            if (!$this->packageRepository->exists($this->package)) {
21
                $this->packageRepository->insert($this->package);
22
            }
23
        } else {
24
            try {
25
                $this->package->update();
26
                $this->packageRepository->save($this->packages);
0 ignored issues
show
Bug introduced by
The property packages does not seem to exist. Did you mean package?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
            } catch (\Exception $e) {
28
                Yii::error('Failed to update package "' . $this->package->getFullName() . '": ' . $e->getMessage(), __CLASS__);
29
                throw $e;
30
            }
31
32
            Yii::$app->queue->push('package', Yii::createObject(CollectDependenciesCommand::class, [$this->package]));
33
        }
34
35
36
        $this->afterRun();
37
    }
38
}
39