Conditions | 10 |
Paths | 21 |
Total Lines | 39 |
Lines | 0 |
Ratio | 0 % |
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:
1 | <?php |
||
66 | public function run () |
||
67 | { |
||
68 | // analyze first input stream part: read targets |
||
69 | // only tokens with length > sensitivity are considered. |
||
70 | $targets=[]; |
||
71 | |||
72 | while (($data=fgetcsv($this->inputStream)) && isset($data[1])) { |
||
73 | assert( $data[0] && $data[1] ) ; |
||
74 | |||
75 | $subjectUri=$data[0]; |
||
76 | $string=$data[1]; |
||
77 | |||
78 | // tokenize string |
||
79 | $tokenizedString=[]; |
||
80 | $tok= strtok($string, ' '); |
||
81 | while ($tok !== false) { |
||
82 | // ignore too short tokens |
||
83 | if( floor(strlen($tok)*$this->sensitivity)>0) { $tokenizedString[]=strtolower($tok);} |
||
84 | $tok = strtok(' '); |
||
85 | } |
||
86 | |||
87 | if( !empty($tokenizedString) ) { $targets[$subjectUri]=$tokenizedString;} |
||
88 | } |
||
89 | |||
90 | //analyze second input stream part: token to be searched in targets |
||
91 | fwrite($this->outputStream, "INSERT DATA { GRAPH <$this->graphName> {\n"); |
||
92 | |||
93 | while (($data = fgetcsv($this->inputStream)) !== FALSE) { |
||
94 | |||
95 | assert( $data[0] && $data[1] ) ; |
||
96 | |||
97 | list ($uri, $token)=$data; |
||
98 | if( $closestUri=$this->findClosestUriToToken( strtolower($token), $targets) ){ |
||
99 | fprintf($this->outputStream, "<%s> <%s> <%s>.\n", $closestUri, $this->property, $uri); |
||
100 | } |
||
101 | |||
102 | } |
||
103 | fwrite($this->outputStream, "}}"); |
||
104 | } |
||
105 | } |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.