Conditions | 7 |
Paths | 10 |
Total Lines | 119 |
Code Lines | 83 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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:
1 | <?php |
||
45 | public function __construct() |
||
46 | { |
||
47 | $this->crypt = new Crypt(); |
||
48 | |||
49 | /** |
||
50 | * Special character |
||
51 | */ |
||
52 | $specialCharacters = [ |
||
53 | "\n", |
||
54 | "\r", |
||
55 | "\t", |
||
56 | '~', |
||
57 | '`', |
||
58 | '!', |
||
59 | '@', |
||
60 | '#', |
||
61 | '$', |
||
62 | '%', |
||
63 | '^', |
||
64 | '&', |
||
65 | '*', |
||
66 | '(', |
||
67 | ')', |
||
68 | '-', |
||
69 | '_', |
||
70 | '=', |
||
71 | '+', |
||
72 | '{', |
||
73 | '}', |
||
74 | '[', |
||
75 | ']', |
||
76 | ':', |
||
77 | ';', |
||
78 | '"', |
||
79 | "'", |
||
80 | '<', |
||
81 | '>', |
||
82 | '/', |
||
83 | '?', |
||
84 | '\\', |
||
85 | '|', |
||
86 | '.', |
||
87 | ',', |
||
88 | ]; |
||
89 | |||
90 | // ------------------------------------------------------------------------ |
||
91 | |||
92 | /** |
||
93 | * Lowercase letter character |
||
94 | */ |
||
95 | $lowerLetterCharacter = [ |
||
96 | 'a', |
||
97 | 'b', |
||
98 | 'c', |
||
99 | 'd', |
||
100 | 'e', |
||
101 | 'f', |
||
102 | 'g', |
||
103 | 'h', |
||
104 | 'i', |
||
105 | 'j', |
||
106 | 'k', |
||
107 | 'l', |
||
108 | 'm', |
||
109 | 'n', |
||
110 | 'o', |
||
111 | 'p', |
||
112 | 'q', |
||
113 | 'r', |
||
114 | 's', |
||
115 | 't', |
||
116 | 'u', |
||
117 | 'v', |
||
118 | 'w', |
||
119 | 'x', |
||
120 | 'y', |
||
121 | 'z', |
||
122 | ]; |
||
123 | |||
124 | // ------------------------------------------------------------------------ |
||
125 | |||
126 | /** |
||
127 | * Uppercase letter character |
||
128 | */ |
||
129 | $upperLetterCharacter = array_map('strtoupper', $lowerLetterCharacter); |
||
130 | |||
131 | // ------------------------------------------------------------------------ |
||
132 | |||
133 | /** |
||
134 | * Binary character |
||
135 | */ |
||
136 | $numericCharacter = range(0, 9, 1); |
||
137 | |||
138 | // ------------------------------------------------------------------------ |
||
139 | |||
140 | static::$charactersMap = array_merge( |
||
|
|||
141 | $specialCharacters, |
||
142 | $lowerLetterCharacter, |
||
143 | $upperLetterCharacter, |
||
144 | $numericCharacter |
||
145 | ); |
||
146 | |||
147 | if (class_exists('\O2System\Framework', false) or class_exists('\O2System\Reactor', false)) { |
||
148 | $key = config()->getItem('security')->offsetGet('encryptionKey'); |
||
149 | $letters = str_split($key); |
||
150 | $cryptoKey = 0; |
||
151 | |||
152 | foreach ($letters as $letter) { |
||
153 | if ($number = array_search($letter, static::$charactersMap)) { |
||
154 | $cryptoKey = $cryptoKey + $number; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $charactersMap = static::$charactersMap; |
||
159 | static::$charactersMap = []; |
||
160 | |||
161 | if ($cryptoKey > 0) { |
||
162 | foreach ($charactersMap as $key => $value) { |
||
163 | static::$charactersMap[ $key * $cryptoKey ] = $value; |
||
164 | } |
||
244 | } |