Completed
Push — master ( b949ee...89218a )
by Martijn van
02:38
created

ConsoleController::publish()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
use Symfony\Component\Console\Application;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Application.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use Symfony\Component\Console\Input\ArgvInput;
5
6
/**
7
 * Class ConsoleController
8
 * The Central Command Access Point and Bootstrapper
9
 */
10
class ConsoleController extends Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    /**
13
     * @var array
14
     */
15
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'publish'
17
    );
18
19
    public function publish()
20
    {
21
        if (Director::is_cli()) {
22
            $this->writesupersakefile();
23
            $this->writehtaccess();
0 ignored issues
show
Unused Code introduced by
The call to the method ConsoleController::writehtaccess() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
24
            $this->writewebconfig();
25
        }
26
    }
27
28
    protected function writesupersakefile()
29
    {
30
        file_put_contents(
31
            BASE_PATH . '/supersake',
32
            file_get_contents(BASE_PATH . '/console/publish/supersake')
33
        );
34
    }
35
36
    /**
37
     * protect the supersake file with htaccess
38
     */
39
    protected function writehtaccess()
40
    {
41
        $content = "# Deny access to supersake
0 ignored issues
show
Unused Code introduced by
$content 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...
42
<Files supersake>
43
	Order allow,deny
44
	Deny from all
45
</Files>";
46
47
    }
48
49
    /**
50
     * protect the supersake file with web.config
51
     */
52
    public function writewebconfig()
53
    {
54
        //<add fileExtension="supersake" allowed="false"/>
55
    }
56
57
58
}
59