GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Pull Request — master (#91)
by
unknown
07:24
created

Configuration::createAccountsNode()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 128
Code Lines 116

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 128
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 116
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Lexik\Bundle\PayboxBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files
10
 *
11
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    public function getConfigTreeBuilder()
19
    {
20
        $treeBuilder = new TreeBuilder();
21
        $rootNode = $treeBuilder->root('lexik_paybox');
22
23
        $rootNode
24
            ->addDefaultsIfNotSet()
25
            ->children()
26
                ->append($this->createAccountsNode())
27
            ->end()
28
        ;
29
30
        return $treeBuilder;
31
    }
32
33
    private function createAccountsNode()
34
    {
35
        $treeBuilder = new TreeBuilder();
36
        $node = $treeBuilder->root('accounts');
37
38
        $node
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Config...\Builder\NodeDefinition as the method children() does only exist in the following sub-classes of Symfony\Component\Config...\Builder\NodeDefinition: Symfony\Component\Config...der\ArrayNodeDefinition. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
39
            ->useAttributeAsKey('name')
40
            ->prototype('array')
41
                ->children()
42
                    ->scalarNode('public_key')->defaultValue(null)->end()
43
44
                    ->arrayNode('parameters')
45
                        ->isRequired()
46
                        ->children()
47
                            ->scalarNode('production')->defaultValue(false)->end()
48
                            ->arrayNode('currencies')
49
                                ->defaultValue(array(
50
                                    '036', // AUD
51
                                    '124', // CAD
52
                                    '756', // CHF
53
                                    '826', // GBP
54
                                    '840', // USD
55
                                    '978', // EUR
56
                                ))
57
                                ->prototype('scalar')->end()
58
                            ->end()
59
                            ->scalarNode('site')->isRequired()->end()
60
                            ->scalarNode('rank')->defaultValue(null)->end()
61
                            ->scalarNode('rang')->defaultValue(null)->end()
62
                            ->scalarNode('login')->defaultValue(null)->end()
63
                            ->scalarNode('cle')->defaultValue(null)->end()
64
                            ->arrayNode('hmac')
65
                                ->isRequired()
66
                                ->children()
67
                                    ->scalarNode('algorithm')->defaultValue('sha512')->end()
68
                                    ->scalarNode('key')->isRequired()->end()
69
                                    ->scalarNode('signature_name')->defaultValue('Sign')->end()
70
                                ->end()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
75
                    ->arrayNode('servers')
76
                        ->addDefaultsIfNotSet()
77
                        ->children()
78
79
                            ->arrayNode('system')
80
                                ->addDefaultsIfNotSet()
81
                                ->children()
82
                                    ->arrayNode('primary')
83
                                        ->addDefaultsIfNotSet()
84
                                        ->children()
85
                                            ->scalarNode('protocol')->defaultValue('https')->end()
86
                                            ->scalarNode('host')->defaultValue('tpeweb.paybox.com')->end()
87
                                            ->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
88
                                            ->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
89
                                            ->scalarNode('test_path')->defaultValue('/load.html')->end()
90
                                        ->end()
91
                                    ->end()
92
                                    ->arrayNode('secondary')
93
                                        ->addDefaultsIfNotSet()
94
                                        ->children()
95
                                            ->scalarNode('protocol')->defaultValue('https')->end()
96
                                            ->scalarNode('host')->defaultValue('tpeweb1.paybox.com')->end()
97
                                            ->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
98
                                            ->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
99
                                            ->scalarNode('test_path')->defaultValue('/load.html')->end()
100
                                        ->end()
101
                                    ->end()
102
                                    ->arrayNode('preprod')
103
                                        ->addDefaultsIfNotSet()
104
                                        ->children()
105
                                            ->scalarNode('protocol')->defaultValue('https')->end()
106
                                            ->scalarNode('host')->defaultValue('preprod-tpeweb.paybox.com')->end()
107
                                            ->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
108
                                            ->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
109
                                            ->scalarNode('test_path')->defaultValue('/load.html')->end()
110
                                        ->end()
111
                                    ->end()
112
                                ->end()
113
                            ->end()
114
115
                            ->arrayNode('direct_plus')
116
                                ->addDefaultsIfNotSet()
117
                                ->children()
118
                                    ->arrayNode('primary')
119
                                        ->addDefaultsIfNotSet()
120
                                        ->children()
121
                                            ->scalarNode('protocol')->defaultValue('https')->end()
122
                                            ->scalarNode('host')->defaultValue('ppps.paybox.com')->end()
123
                                            ->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
124
                                        ->end()
125
                                    ->end()
126
                                    ->arrayNode('secondary')
127
                                        ->addDefaultsIfNotSet()
128
                                        ->children()
129
                                            ->scalarNode('protocol')->defaultValue('https')->end()
130
                                            ->scalarNode('host')->defaultValue('ppps1.paybox.com')->end()
131
                                            ->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
132
                                        ->end()
133
                                    ->end()
134
                                    ->arrayNode('preprod')
135
                                        ->addDefaultsIfNotSet()
136
                                        ->children()
137
                                            ->scalarNode('protocol')->defaultValue('https')->end()
138
                                            ->scalarNode('host')->defaultValue('preprod-ppps.paybox.com')->end()
139
                                            ->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
140
                                        ->end()
141
                                    ->end()
142
                                ->end()
143
                            ->end()
144
145
                        ->end()
146
                    ->end()
147
148
                    ->scalarNode('transport')
149
                        ->defaultValue('Lexik\Bundle\PayboxBundle\Transport\CurlTransport')
150
                        ->validate()
151
                        ->ifTrue(function($v) { return !class_exists($v); })
152
                            ->thenInvalid('Invalid "transport" parameter.')
153
                        ->end()
154
                    ->end()
155
                ->end()
156
            ->end()
157
        ;
158
159
        return $node;
160
    }
161
}
162