Completed
Branch master (d7ed14)
by Benjamin
08:11 queued 03:45
created

PermissionsTask::getDescription()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the teamneusta/magallanes-task-typo3 package.
4
 *
5
 * Copyright (c) 2017 neusta GmbH | Ein team neusta Unternehmen
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
8
 *
9
 * @license http://www.opensource.org/licenses/mit-license.html  MIT License
10
 */
11
declare(strict_types=1);
12
13
namespace TeamNeusta\Magallanes\Task\TYPO3;
14
15
/**
16
 * Class PermissionsTask
17
 *
18
 * @author Benjamin Kluge <[email protected]>
19
 * @package TeamNeusta\Magallanes\Task\TYPO3
20
 */
21
class PermissionsTask extends AbstractTypo3Task
22
{
23
    /**
24
     * name
25
     *
26
     * @var string
27
     */
28
    protected $name = 'permissions';
29
30
    /**
31
     * description
32
     *
33
     * @var string
34
     */
35
    protected $description = '[TYPO3] TYPO3 permissions task';
36
37
    /**
38
     * permissions
39
     *
40
     * @var array
41
     */
42
    protected $permissions = [
43
        '/typo3conf/PackageStates.php'      => 2775,
44
        '/typo3conf/LocalConfiguration.php' => 2775,
45
    ];
46
47
    /**
48
     * execute
49
     *
50
     * @return bool
51
     */
52
    public function execute(): bool
53
    {
54
        $options = $this->getOptions(['web-dir' => 'web']);
55
        foreach ($this->permissions as $path => $permission) {
56
            $command = sprintf('chmod -f %s "%s"', $permission, $options['web-dir'].$path);
57
            $process = $this->executeCommand($command);
58
        }
59
60
        return $process;
0 ignored issues
show
Bug introduced by
The variable $process does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
61
    }
62
}
63