Conditions | 11 |
Paths | 15 |
Total Lines | 58 |
Code Lines | 47 |
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 |
||
101 | public function process(TileInterface $tile, SpecificationInterface $specification) |
||
102 | { |
||
103 | $image = $tile->getImage(); |
||
104 | $width = $image->getWidth(); |
||
105 | $height = $image->getHeight(); |
||
106 | $colorGrid = new ColorGrid(); |
||
107 | $lumaGrid = new LumaGrid(); |
||
108 | $target = $this->imageFactory->create($width, $height); |
||
109 | $edge = new Edge(); |
||
110 | $edge->image = $image; |
||
111 | $edge->color = $colorGrid; |
||
112 | $edge->luma = $lumaGrid; |
||
113 | for ($x = 0; $x < $width; $x++) { |
||
114 | for ($y = 0; $y < $height; $y++) { |
||
115 | $edge->x = $x; |
||
116 | $edge->y = $y; |
||
117 | |||
118 | // Gathering 3x3 grid data |
||
119 | $colorGrid->fill($image, $x, $y); |
||
120 | $lumaGrid->fill($colorGrid); |
||
121 | |||
122 | // High luma range tells there is an edge in 3x3 box |
||
123 | if ($lumaGrid->range < max($lumaGrid->max * $this->edgeThreshold, $this->minimumEdgeThreshold)) { |
||
124 | // So if there's no such thing, let's just jump to next pixel |
||
125 | $target->setColorAt($x, $y, $colorGrid->center); |
||
126 | continue; |
||
127 | } |
||
128 | EdgeOrientationCalculator::apply($edge); |
||
129 | EdgeDirectionCalculator::apply($edge); |
||
130 | EdgeLumaCalculator::apply($edge); |
||
131 | EdgeDistanceCalculator::apply($edge); |
||
132 | $offset = SubPixelOffsetCalculator::calculate($edge); |
||
133 | switch ($this->debug) { |
||
134 | case self::DEBUG_EDGE: |
||
135 | $alpha = (int) ($offset * 2 * 255); |
||
136 | $yellow = 0xFFFF00FF; |
||
137 | $yellow = $yellow & ($alpha | 0xFFFFFF00); |
||
138 | $color = Color::blend(0xFF0000FF, $yellow); |
||
139 | $target->setColorAt($x, $y, $color); |
||
140 | break; |
||
141 | case self::DEBUG_ORIENTATION: |
||
142 | $color = $edge->horizontal ? 0xFFFF00FF : 0x0000FFFF; |
||
143 | $target->setColorAt($x, $y, $color); |
||
144 | break; |
||
145 | case self::DEBUG_PAIR: |
||
146 | $target->setColorAt($x, $y, 0x0000FFFF); |
||
147 | $value = $edge->inward ? -1 : 1; |
||
148 | $xOffset = $edge->horizontal ? 0 : $value; |
||
149 | $yOffset = $edge->horizontal ? $value : 0; |
||
150 | $target->setColorAt($x + $xOffset, $y + $yOffset, 0x00FF00FF); |
||
151 | break; |
||
152 | default: |
||
153 | $color = TargetColorCalculator::calculate($edge, $offset); |
||
154 | $target->setColorAt($x, $y, $color); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | return new Tile($tile->getPosition(), $target); |
||
159 | } |
||
167 |