Conditions | 8 |
Paths | 128 |
Total Lines | 61 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 50.2896 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
85 | public function __construct(ResourceOwnerProviderInterface $resourceOwnerProvider, |
||
86 | StorageRepository $storageRepository, |
||
87 | ConfigurationRepository $configurationRepository = null, |
||
88 | ?ResponseTypeRepository $responseTypeRepository = null, |
||
89 | ?GrantTypeRepository $grantTypeRepository = null, |
||
90 | ?ClientAuthenticatorRepository $clientAuthenticatorRepository = null, |
||
91 | ?Guard $guard = null, |
||
92 | ?Manager $scopePolicyManager = null, |
||
93 | ?ResponseModeRepository $responseModeRepository = null) |
||
94 | { |
||
95 | $this->resourceOwnerProvider = $resourceOwnerProvider; |
||
96 | $this->storageRepository = $storageRepository; |
||
97 | |||
98 | |||
99 | if (is_null($configurationRepository)) { |
||
100 | $this->configurationRepository = new ConfigurationRepository(); |
||
101 | } else { |
||
102 | $this->configurationRepository = $configurationRepository; |
||
103 | } |
||
104 | |||
105 | if (is_null($responseTypeRepository)) { |
||
106 | $this->responseTypeRepository = new ResponseTypeRepository( |
||
107 | ResponseTypeRepository::getDefaultResponseTypes($this)); |
||
108 | } else { |
||
109 | $this->responseTypeRepository = $responseTypeRepository; |
||
110 | } |
||
111 | |||
112 | if (is_null($clientAuthenticatorRepository)) { |
||
113 | $this->clientAuthenticatorRepository = new ClientAuthenticatorRepository( |
||
114 | ClientAuthenticatorRepository::getDefaultAuthenticators( |
||
115 | $this->configurationRepository, $this->storageRepository)); |
||
116 | } else { |
||
117 | $this->clientAuthenticatorRepository = $responseTypeRepository; |
||
|
|||
118 | } |
||
119 | |||
120 | $this->guard = $guard ? $guard : new Guard($this); |
||
121 | // var_dump($this->guard);die; |
||
122 | $this->scopePolicyManager = $scopePolicyManager ? $scopePolicyManager : new Manager($this); |
||
123 | |||
124 | if (is_null($grantTypeRepository)) { |
||
125 | $this->grantTypeRepository = new GrantTypeRepository( |
||
126 | GrantTypeRepository::getDefaultGrantTypes( |
||
127 | $this->configurationRepository, |
||
128 | $this->resourceOwnerProvider, |
||
129 | $this->scopePolicyManager, |
||
130 | $this->storageRepository)); |
||
131 | } else { |
||
132 | $this->grantTypeRepository = $grantTypeRepository; |
||
133 | } |
||
134 | |||
135 | 4 | ||
136 | |||
137 | 4 | if (is_null($responseModeRepository)) { |
|
138 | $this->responseModeRepository = new ResponseModeRepository( |
||
139 | ResponseModeRepository::getDefaultResponseModes()); |
||
140 | } else { |
||
141 | $this->responseModeRepository = $responseModeRepository; |
||
142 | } |
||
143 | 4 | ||
144 | $this->authorizationEndpoint = new AuthorizationEndpoint($this); |
||
145 | 4 | $this->tokenEndpoint = new TokenEndpoint($this); |
|
146 | } |
||
265 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.