PluginUpgradeCommand::getPluginDetails()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Console;
13
14
use Jitamin\Foundation\Plugin\Base as BasePlugin;
15
use Jitamin\Foundation\Plugin\Directory;
16
use Jitamin\Foundation\Plugin\Installer;
17
use LogicException;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Plugin Upgrade command class.
23
 */
24
class PluginUpgradeCommand extends BaseCommand
25
{
26
    /**
27
     * Configure the console command.
28
     *
29
     * @return void
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->setName('plugin:upgrade')
35
            ->setDescription('Update all installed plugins');
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @param InputInterface  $output
42
     * @param OutputInterface $output
43
     *
44
     * @return void
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        if (!Installer::isConfigured()) {
49
            throw new LogicException('Jitamin is not configured to install plugins itself');
50
        }
51
52
        $installer = new Installer($this->container);
53
        $availablePlugins = Directory::getInstance($this->container)->getAvailablePlugins();
54
55
        foreach ($this->pluginLoader->getPlugins() as $installedPlugin) {
0 ignored issues
show
Documentation introduced by
The property pluginLoader does not exist on object<Jitamin\Console\PluginUpgradeCommand>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
56
            $pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin);
57
58
            if ($pluginDetails === null) {
59
                $output->writeln('<error>* Plugin not available in the directory: '.$installedPlugin->getPluginName().'</error>');
60
            } elseif ($pluginDetails['version'] > $installedPlugin->getPluginVersion()) {
61
                $output->writeln('<comment>* Updating plugin: '.$installedPlugin->getPluginName().'</comment>');
62
                $installer->update($pluginDetails['download']);
63
            } else {
64
                $output->writeln('<info>* Plugin up to date: '.$installedPlugin->getPluginName().'</info>');
65
            }
66
        }
67
    }
68
69
    /**
70
     * Get plugin details.
71
     *
72
     * @param array      $availablePlugins
73
     * @param BasePlugin $installedPlugin
74
     *
75
     * @return mixed
76
     */
77
    protected function getPluginDetails(array $availablePlugins, BasePlugin $installedPlugin)
78
    {
79
        foreach ($availablePlugins as $availablePlugin) {
80
            if ($availablePlugin['title'] === $installedPlugin->getPluginName()) {
81
                return $availablePlugin;
82
            }
83
        }
84
    }
85
}
86