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

PackageUpdateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 26
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 23 4
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