Passed
Push — master ( 7f3591...9d865c )
by Anthony
02:49
created

UpdatePackagesInfo::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
4
namespace PiouPiou\RibsAdminBundle\Command;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use PiouPiou\RibsAdminBundle\Entity\Package;
8
use PiouPiou\RibsAdminBundle\Service\Version;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class UpdatePackagesInfo extends Command
14
{
15
    /**
16
     * @var EntityManagerInterface
17
     */
18
    private $em;
19
20
    /**
21
     * @var Version
22
     */
23
    private $version;
24
25
    /**
26
     * ImportModuleCommand constructor.
27
     * @param EntityManagerInterface $em
28
     * @param Version $version
29
     * @param string|null $name
30
     */
31
    public function __construct(EntityManagerInterface $em, Version $version, string $name = null)
32
    {
33
        parent::__construct($name);
34
        $this->em = $em;
35
        $this->version = $version;
36
    }
37
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('ribsadmin:update-packages-info')
42
            ->setDescription('Update all packages versions informatio')
43
        ;
44
    }
45
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $packages = $this->em->getRepository(Package::class)->findAll();
49
50
        /** @var Package $package */
51
        foreach ($packages as $package) {
52
            $output->writeln("Update ".$package->getPackageName()." info");
53
            $this->version->save($package->getGuid());
54
        }
55
56
        return 0;
57
    }
58
}
59