BundleVersion   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 13 3
A getBundles() 0 10 3
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