Theme::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-present LIN3S <[email protected]>
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 LIN3S\WPFoundation\Configuration\Theme;
13
14
/**
15
 * Abstract class of theme that implements the interface.
16
 * This class avoids the use of callbacks in the constructor.
17
 *
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
abstract class Theme implements ThemeInterface
21
{
22
    /**
23
     * Constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->classes();
28
        $this->templateSelector();
0 ignored issues
show
Unused Code introduced by
The call to the method LIN3S\WPFoundation\Confi...eme::templateSelector() 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...
29
        $this->xmlrpc();
30
        add_theme_support('post-thumbnails');
0 ignored issues
show
Unused Code introduced by
The call to the function add_theme_support() seems unnecessary as the function has no side-effects.
Loading history...
31
        add_filter('timber_context', [$this, 'context']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
32
33
        // @deprecated since version 1.6, will be removed in 2.0. Extend the ACF class in your project and instantiate
34
        // inside your project Theme.
35
        $this->acf();
0 ignored issues
show
Unused Code introduced by
The call to the method LIN3S\WPFoundation\Confi...tion\Theme\Theme::acf() 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...
Deprecated Code introduced by
The method LIN3S\WPFoundation\Confi...tion\Theme\Theme::acf() has been deprecated with message: since version 1.6, will be removed in 2.0. Extend the ACF class in your project and instantiate inside your project Theme

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36
    }
37
38
    /**
39
     * Filters the selectable templates.
40
     */
41
    private function templateSelector()
42
    {
43
        $self = $this;
44
        add_filter('theme_page_templates', function () use ($self) {
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
45
            return $self->templates([]);
46
        });
47
    }
48
49
    /**
50
     * Enables or disables XML-RPC feature.
51
     */
52
    private function xmlrpc()
53
    {
54
        $xmlrpc = !defined('XMLRPC_ENABLED') || XMLRPC_ENABLED === true
55
            ? '__return_true'
56
            : '__return_false';
57
        add_filter('xmlrpc_enabled', $xmlrpc);
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
58
    }
59
60
    /**
61
     * @deprecated since version 1.6, will be removed in 2.0. Extend the ACF class in your project and instantiate
62
     *             inside your project Theme
63
     */
64
    protected function acf()
65
    {
66
        $customToolbars = [
67
            'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']],
68
        ];
69
70
        add_filter('acf/fields/wysiwyg/toolbars', function (array $toolbars) use ($customToolbars) {
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
71
            return array_merge($toolbars, $customToolbars);
72
        });
73
    }
74
}
75