Completed
Push — master ( 60399b...890f86 )
by Craig
06:15
created

AbstractRoutesModuleInstaller   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A install() 0 21 2
B upgrade() 0 25 1
A uninstall() 0 19 2
A listEntityClasses() 0 7 1
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.5 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Base;
14
15
use RuntimeException;
16
use Zikula\Core\AbstractExtensionInstaller;
17
18
/**
19
 * Installer base class.
20
 */
21
abstract class AbstractRoutesModuleInstaller extends AbstractExtensionInstaller
22
{
23
    /**
24
     * Install the ZikulaRoutesModule application.
25
     *
26
     * @return boolean True on success, or false
27
     *
28
     * @throws RuntimeException Thrown if database tables can not be created or another error occurs
29
     */
30
    public function install()
31
    {
32
        $logger = $this->container->get('logger');
33
        $userName = $this->container->get('zikula_users_module.current_user')->get('uname');
0 ignored issues
show
Unused Code introduced by
$userName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
    
35
        // create all tables from according entity definitions
36
        try {
37
            $this->schemaTool->create($this->listEntityClasses());
38
        } catch (\Exception $e) {
39
            $this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage());
40
            $logger->error('{app}: Could not create the database tables during installation. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]);
41
    
42
            return false;
43
        }
44
    
45
        // set up all our vars with initial values
46
        $this->setVar('routeEntriesPerPage', '10');
47
    
48
        // initialisation successful
49
        return true;
50
    }
51
    
52
    /**
53
     * Upgrade the ZikulaRoutesModule application from an older version.
54
     *
55
     * If the upgrade fails at some point, it returns the last upgraded version.
56
     *
57
     * @param integer $oldVersion Version to upgrade from
58
     *
59
     * @return boolean True on success, false otherwise
60
     *
61
     * @throws RuntimeException Thrown if database tables can not be updated
62
     */
63
    public function upgrade($oldVersion)
64
    {
65
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        $logger = $this->container->get('logger');
67
    
68
        // Upgrade dependent on old version number
69
        switch ($oldVersion) {
70
            case '1.0.0':
71
                // do something
72
                // ...
73
                // update the database schema
74
                try {
75
                    $this->schemaTool->update($this->listEntityClasses());
76
                } catch (\Exception $e) {
77
                    $this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage());
78
                    $logger->error('{app}: Could not update the database tables during the upgrade. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]);
79
    
80
                    return false;
81
                }
82
        }
83
    */
84
    
85
        // update successful
86
        return true;
87
    }
88
    
89
    /**
90
     * Uninstall ZikulaRoutesModule.
91
     *
92
     * @return boolean True on success, false otherwise
93
     *
94
     * @throws RuntimeException Thrown if database tables or stored workflows can not be removed
95
     */
96
    public function uninstall()
97
    {
98
        $logger = $this->container->get('logger');
99
    
100
        try {
101
            $this->schemaTool->drop($this->listEntityClasses());
102
        } catch (\Exception $e) {
103
            $this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage());
104
            $logger->error('{app}: Could not remove the database tables during uninstallation. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]);
105
    
106
            return false;
107
        }
108
    
109
        // remove all module vars
110
        $this->delVars();
111
    
112
        // uninstallation successful
113
        return true;
114
    }
115
    
116
    /**
117
     * Build array with all entity classes for ZikulaRoutesModule.
118
     *
119
     * @return array list of class names
120
     */
121
    protected function listEntityClasses()
122
    {
123
        $classNames = [];
124
        $classNames[] = 'Zikula\RoutesModule\Entity\RouteEntity';
125
    
126
        return $classNames;
127
    }
128
}
129