Completed
Push — master ( 7738c1...bafc4e )
by Nicolaas
01:18
created

WebpackPageControllerExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A IsNotWebpackDevServer() 0 4 2
A IsWebpackDevServer() 0 7 3
A WebpackBaseURL() 0 9 2
A WebpackDistributionFolderExtension() 0 4 1
1
<?php
2
3
4
class WebpackPageControllerExtension extends extension
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...
5
{
6
7
    /**
8
     *
9
     * @var {Array}
10
     */
11
    private static $webpack_enabled_themes = [];
0 ignored issues
show
Unused Code introduced by
The property $webpack_enabled_themes 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...
12
13
    /**
14
     *
15
     * @var int
16
     */
17
    private static $webpack_port = 3000;
0 ignored issues
show
Unused Code introduced by
The property $webpack_port 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...
18
19
20
    /**
21
     *
22
     * @var string
23
     */
24
    private static $webpack_distribution_folder_extension = 'dist';
0 ignored issues
show
Unused Code introduced by
The property $webpack_distribution_folder_extension 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...
25
26
    /**
27
     *
28
     * @return bool
29
     */
30
    public function IsNotWebpackDevServer()
31
    {
32
        return $this->IsWebpackDevServer() ? false : true;
33
    }
34
35
36
    /**
37
     *
38
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40
    public function IsWebpackDevServer()
41
    {
42
        if (Director::isDev()) {
43
            $socket = @fsockopen('localhost', $this->owner->Config()->get('webpack_port'), $errno, $errstr, 1);
44
            return !$socket ? false : true;
45
        }
46
    }
47
48
49
    /**
50
     *
51
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be false|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
     */
53
    public function WebpackBaseURL()
54
    {
55
        $str = Director::AbsoluteBaseURL('/');
0 ignored issues
show
Unused Code introduced by
The call to Director::absoluteBaseURL() has too many arguments starting with '/'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56
        if($this->IsWebpackDevServer()) {
57
            $str = rtrim($str, '/') .':'.$this->owner->Config()->get('webpack_port').'/';
58
        }
59
60
        return $str;
61
    }
62
63
    public function WebpackDistributionFolderExtension()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
64
    {
65
        return $this->owner->Config()->get('webpack_distribution_folder_extension');
66
    }
67
}
68