BundleVersion::getBundles()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace kujaff\VersionsBundle\Service;
4
5
use kujaff\VersionsBundle\Entity\BundleVersion as BundleVersionEntity;
6
use Symfony\Component\DependencyInjection\ContainerAware;
7
use kujaff\VersionsBundle\Model\VersionnedBundle;
8
9
/**
10
 * Service for BundleVersions
11
 */
12
class BundleVersion extends ContainerAware
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Depend...njection\ContainerAware has been deprecated with message: since version 2.8, to be removed in 3.0. Use the ContainerAwareTrait instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
13
{
14
15
    /**
16
     * Get bundle version informations
17
     *
18
     * @param string $bundle
19
     * @return BundleVersionEntity
20
     */
21
    public function getVersion($bundle)
22
    {
23
        $doctrine = $this->container->get('doctrine');
24
        $return = $doctrine->getRepository('VersionsBundle:BundleVersion')->findOneByName($bundle);
25
        if ($return === null) {
26
            $return = new BundleVersionEntity($bundle);
27
        }
28
        $bundle = $this->container->get('kernel')->getBundle($bundle);
29
        if ($bundle instanceof VersionnedBundle) {
30
            $return->setVersion($bundle->getVersion());
31
        }
32
        return $return;
33
    }
34
35
    /**
36
     * Get versionned bundles
37
     *
38
     * @return BundleVersionEntity[]
39
     */
40
    public function getBundles()
41
    {
42
        $return = array();
43
        foreach ($this->container->get('kernel')->getBundles() as $bundle) {
44
            if ($bundle instanceof VersionnedBundle) {
45
                $return[] = $this->getVersion($bundle->getName());
46
            }
47
        }
48
        return $return;
49
    }
50
}
51