Completed
Push — master ( 6f2f7b...0abd1b )
by Kamil
16s
created

AppKernel::isVagrantEnvironment()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 3
eloc 2
nc 3
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
13
use Symfony\Component\Config\Loader\LoaderInterface;
14
use Symfony\Component\HttpKernel\Kernel;
15
16
/**
17
 * @author Paweł Jędrzejewski <[email protected]>
18
 * @author Gonzalo Vilaseca <[email protected]>
19
 */
20
class AppKernel extends Kernel
21
{
22
    const VERSION = '0.19.0-dev';
23
    const VERSION_ID = '00190';
24
    const MAJOR_VERSION = '0';
25
    const MINOR_VERSION = '19';
26
    const RELEASE_VERSION = '0';
0 ignored issues
show
Best Practice introduced by
The expression return array(new \Symfon...AppBundle\AppBundle()); seems to be an array, but some of its elements' types (Sensio\Bundle\GeneratorB...e\SensioGeneratorBundle) are incompatible with the return type declared by the interface Symfony\Component\HttpKe...erface::registerBundles of type Symfony\Component\HttpKe...undle\BundleInterface[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
27
    const EXTRA_VERSION = 'DEV';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function registerBundles()
33
    {
34
        $bundles = [
35
            new \Sylius\Bundle\InstallerBundle\SyliusInstallerBundle(),
36
            new \Sylius\Bundle\OrderBundle\SyliusOrderBundle(),
37
            new \Sylius\Bundle\MoneyBundle\SyliusMoneyBundle(),
38
            new \Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle(),
39
            new \Sylius\Bundle\ContactBundle\SyliusContactBundle(),
40
            new \Sylius\Bundle\LocaleBundle\SyliusLocaleBundle(),
41
            new \Sylius\Bundle\SettingsBundle\SyliusSettingsBundle(),
42
            new \Sylius\Bundle\CartBundle\SyliusCartBundle(),
43
            new \Sylius\Bundle\ProductBundle\SyliusProductBundle(),
44
            new \Sylius\Bundle\ArchetypeBundle\SyliusArchetypeBundle(),
45
            new \Sylius\Bundle\ChannelBundle\SyliusChannelBundle(),
46
            new \Sylius\Bundle\VariationBundle\SyliusVariationBundle(),
47
            new \Sylius\Bundle\AttributeBundle\SyliusAttributeBundle(),
48
            new \Sylius\Bundle\TaxationBundle\SyliusTaxationBundle(),
49
            new \Sylius\Bundle\ShippingBundle\SyliusShippingBundle(),
50
            new \Sylius\Bundle\PaymentBundle\SyliusPaymentBundle(),
51
            new \Sylius\Bundle\MailerBundle\SyliusMailerBundle(),
52
            new \Sylius\Bundle\ReportBundle\SyliusReportBundle(),
53
            new \Sylius\Bundle\PromotionBundle\SyliusPromotionBundle(),
54
            new \Sylius\Bundle\AddressingBundle\SyliusAddressingBundle(),
55
            new \Sylius\Bundle\InventoryBundle\SyliusInventoryBundle(),
56
            new \Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle(),
57
            new \Sylius\Bundle\FlowBundle\SyliusFlowBundle(),
58
            new \Sylius\Bundle\PricingBundle\SyliusPricingBundle(),
59
            new \Sylius\Bundle\SequenceBundle\SyliusSequenceBundle(),
60
            new \Sylius\Bundle\ContentBundle\SyliusContentBundle(),
61
            new \Sylius\Bundle\SearchBundle\SyliusSearchBundle(),
62
            new \Sylius\Bundle\RbacBundle\SyliusRbacBundle(),
63
            new \Sylius\Bundle\UserBundle\SyliusUserBundle(),
64
            new \Sylius\Bundle\UiBundle\SyliusUiBundle(),
65
            new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(),
66
            new \Sylius\Bundle\ShopBundle\SyliusShopBundle(),
67
            new \Sylius\Bundle\MetadataBundle\SyliusMetadataBundle(),
68
            new \Sylius\Bundle\AssociationBundle\SyliusAssociationBundle(),
69
            new \Sylius\Bundle\ReviewBundle\SyliusReviewBundle(),
70
            new \Sylius\Bundle\CoreBundle\SyliusCoreBundle(),
71
            new \Sylius\Bundle\WebBundle\SyliusWebBundle(),
72
            new \Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
73
            new \Sylius\Bundle\GridBundle\SyliusGridBundle(),
74
            new \winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(),
75
            new \Sylius\Bundle\ApiBundle\SyliusApiBundle(),
76
77
            new \Sonata\BlockBundle\SonataBlockBundle(),
78
            new \Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(),
79
            new \Symfony\Cmf\Bundle\BlockBundle\CmfBlockBundle(),
80
            new \Symfony\Cmf\Bundle\ContentBundle\CmfContentBundle(),
81
            new \Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
82
            new \Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
83
            new \Symfony\Cmf\Bundle\CreateBundle\CmfCreateBundle(),
84
            new \Symfony\Cmf\Bundle\MediaBundle\CmfMediaBundle(),
85
86
            new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
87
            new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
88
            new \Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
89
            new \Symfony\Bundle\AsseticBundle\AsseticBundle(),
90
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
91
            new \Symfony\Bundle\MonologBundle\MonologBundle(),
92
            new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
93
            new \Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
94
            new \Symfony\Bundle\TwigBundle\TwigBundle(),
95
96
            new \Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle(),
97
            new \FOS\OAuthServerBundle\FOSOAuthServerBundle(),
98
            new \FOS\RestBundle\FOSRestBundle(),
99
100
            new \FOS\ElasticaBundle\FOSElasticaBundle(),
101
            new \Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
102
            new \Knp\Bundle\MenuBundle\KnpMenuBundle(),
103
            new \Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
104
            new \Liip\ImagineBundle\LiipImagineBundle(),
105
            new \Payum\Bundle\PayumBundle\PayumBundle(),
106
            new \JMS\SerializerBundle\JMSSerializerBundle(),
107
            new \JMS\TranslationBundle\JMSTranslationBundle(),
108
            new \Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
109
            new \WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
110
111
            new \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
112
            new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
113
            new \Sylius\Bundle\FixturesBundle\SyliusFixturesBundle(),
114
            new \Sylius\Bundle\PayumBundle\SyliusPayumBundle(), // must be added after PayumBundle.
115
            new \Sylius\Bundle\ThemeBundle\SyliusThemeBundle(), // must be added after FrameworkBundle
116
        ];
117
118
        if (in_array($this->environment, ['dev', 'test'], true)) {
119
            $bundles[] = new \Symfony\Bundle\DebugBundle\DebugBundle();
120
            $bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
121
        }
122
123
        return $bundles;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    protected function getContainerBaseClass()
130
    {
131
        if ('test' === $this->environment || 'test_cached' === $this->environment) {
132
            return MockerContainer::class;
133
        }
134
135
        return parent::getContainerBaseClass();
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function registerContainerConfiguration(LoaderInterface $loader)
142
    {
143
        $rootDir = $this->getRootDir();
144
145
        $loader->load($rootDir.'/config/config_'.$this->environment.'.yml');
146
147
        if (is_file($file = $rootDir.'/config/config_'.$this->environment.'.local.yml')) {
148
            $loader->load($file);
149
        }
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function getCacheDir()
156
    {
157
        if ($this->isVagrantEnvironment()) {
158
            return '/dev/shm/sylius/cache/'.$this->environment;
159
        }
160
161
        return parent::getCacheDir();
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function getLogDir()
168
    {
169
        if ($this->isVagrantEnvironment()) {
170
            return '/dev/shm/sylius/logs';
171
        }
172
173
        return parent::getLogDir();
174
    }
175
176
    /**
177
     * @return bool
178
     */
179
    protected function isVagrantEnvironment()
180
    {
181
        return (getenv('HOME') === '/home/vagrant' || getenv('VAGRANT') === 'VAGRANT') && is_dir('/dev/shm');
182
    }
183
}
184