Completed
Push — master ( 6090d6...edf18c )
by Craig
09:38 queued 03:17
created

MockHookApi::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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 Zikula\Core;
13
14
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Zikula\Common\Translator\TranslatorTrait;
17
use Zikula\ExtensionsModule\ExtensionVariablesTrait;
18
19
/**
20
 * Installation and upgrade routines for the blocks extension
21
 */
22
abstract class AbstractExtensionInstaller implements ExtensionInstallerInterface, ContainerAwareInterface
23
{
24
    use TranslatorTrait;
25
    use ExtensionVariablesTrait;
26
27
    /**
28
     * @var string the bundle name
29
     */
30
    protected $name;
31
32
    /**
33
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
34
     */
35
    protected $container;
36
37
    /**
38
     * @var AbstractBundle
39
     */
40
    protected $bundle;
41
42
    /**
43
     * @var \Doctrine\ORM\EntityManager
44
     */
45
    protected $entityManager;
46
47
    /**
48
     * @var \Zikula\Core\Doctrine\Helper\SchemaHelper
49
     */
50
    protected $schemaTool;
51
52
    /**
53
     * @var MockHookApi
54
     */
55
    protected $hookApi;
56
57
    /**
58
     * initialise the extension
59
     *
60
     * @return bool true on success, false otherwise
61
     */
62
    abstract public function install();
63
64
    /**
65
     * upgrade the blocks extension
66
     *
67
     * @param string $oldversion version being upgraded
68
     *
69
     * @return bool true if successful, false otherwise
70
     */
71
    abstract public function upgrade($oldversion);
72
73
    /**
74
     * delete the blocks extension
75
     *
76
     * Since the blocks extension should never be deleted we'all always return false here
77
     * @return bool false
78
     */
79
    abstract public function uninstall();
80
81
    public function setBundle(AbstractBundle $bundle)
82
    {
83
        $this->bundle = $bundle;
84
        $this->name = $bundle->getName();
85
        if ($this->container) {
86
            // both here and in `setContainer` so either method can be called first.
87
            $this->container->get('translator')->setDomain($this->bundle->getTranslationDomain());
88
        }
89
        $this->hookApi = new MockHookApi();
0 ignored issues
show
Deprecated Code introduced by
The class Zikula\Core\MockHookApi has been deprecated with message: Remove at Core-3.0
Class MockHookApi
This class only exists to prevent errors where an Installer class tries to call a method like
`$this->hookApi->uninstallSubscriberHooks()`. This method call is no longer required because the tables it populated
have been removed. But a module author may unknowingly leave them in the installer.

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...
90
    }
91
92
    /**
93
     * @param ContainerInterface|null $container
94
     */
95
    public function setContainer(ContainerInterface $container = null)
96
    {
97
        $this->container = $container;
98
        $this->setTranslator($container->get('translator'));
99
        $this->entityManager = $container->get('doctrine')->getManager();
100
        $this->schemaTool = $container->get('zikula_core.common.doctrine.schema_tool');
101
        $this->extensionName = $this->name; // for ExtensionVariablesTrait
102
        $this->variableApi = $container->get('zikula_extensions_module.api.variable'); // for ExtensionVariablesTrait
103
        if ($this->bundle) {
104
            $container->get('translator')->setDomain($this->bundle->getTranslationDomain());
105
        }
106
    }
107
108
    public function setTranslator($translator)
109
    {
110
        $this->translator = $translator;
111
    }
112
113
    /**
114
     * Convenience shortcut to add a session flash message.
115
     * @param $type
116
     * @param $message
117
     */
118 View Code Duplication
    public function addFlash($type, $message)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    {
120
        if (!$this->container->has('session')) {
121
            throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
122
        }
123
124
        $this->container->get('session')->getFlashBag()->add($type, $message);
125
    }
126
}
127
128
/**
129
 * @deprecated Remove at Core-3.0
130
 * Class MockHookApi
131
 * This class only exists to prevent errors where an Installer class tries to call a method like
132
 * `$this->hookApi->uninstallSubscriberHooks()`. This method call is no longer required because the tables it populated
133
 * have been removed. But a module author may unknowingly leave them in the installer.
134
 */
135
class MockHookApi
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
136
{
137
    public function __call($name, $arguments)
138
    {
139
        // intentionally do nothing
140
        @trigger_error('All methods from HookApi are no longer needed. They should be completely removed from the Installer class.');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
141
    }
142
}
143