Conditions | 10 |
Paths | 288 |
Total Lines | 39 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 4 |
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:
1 | <?php |
||
92 | public function __construct(array $data = []) |
||
93 | { |
||
94 | foreach ($data as $key => $value) { |
||
95 | $attribute = camel_case($key); |
||
96 | |||
97 | if (property_exists($this, $attribute)) { |
||
98 | $this->{$attribute} = $value; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | if (empty($this->iss)) { |
||
103 | $this->iss = Config::get('app.url'); |
||
104 | } |
||
105 | |||
106 | if (empty($this->iat)) { |
||
107 | $this->iat = Carbon::now()->timestamp; |
||
108 | } |
||
109 | |||
110 | if (empty($this->exp)) { |
||
111 | $ttl = $this->refresh ? Config::get('jwt.refresh_ttl') : Config::get('jwt.ttl'); |
||
112 | $this->exp = $this->iat + ($ttl * 60); // turns minute into second |
||
|
|||
113 | } |
||
114 | |||
115 | if (empty($this->nat)) { |
||
116 | $this->nat = $this->iat + (Config::get('jwt.ttl') * 60); // turns minute into second |
||
117 | } |
||
118 | |||
119 | if (empty($this->jti)) { |
||
120 | $this->jti = md5("{$this->sub}.{$this->iat}." . rand(1000, 1999)); |
||
121 | } |
||
122 | |||
123 | if (empty($this->leeway)) { |
||
124 | $this->leeway = Config::get('jwt.leeway'); |
||
125 | } |
||
126 | |||
127 | $this->now = Carbon::now()->timestamp; |
||
128 | |||
129 | $this->validate(); |
||
130 | } |
||
131 | |||
210 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.