Conditions | 3 |
Paths | 3 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
33 | public function execute(Image $image) |
||
34 | { |
||
35 | $originImage = $image; |
||
36 | |||
37 | $outputFilepathname = Filename::createTempFilename(); |
||
38 | |||
39 | $inputFile = FileTempObject::fromString($originImage->toPNG()->getContent()); |
||
40 | |||
41 | /** @var MultiCoordinateCommandOption $options */ |
||
42 | $options = $this->options; |
||
43 | |||
44 | if (!$options->isQuadrilateral()) { |
||
45 | throw new InvalidArgumentException('Coordinates must represent a quadrilateral shape'); |
||
46 | } |
||
47 | |||
48 | $options = GeometryUtils::getClockwiseOrder($options); |
||
49 | |||
50 | /** @var Coordinate[] $coordinates */ |
||
51 | $coordinates = $options->toArray(); |
||
52 | |||
53 | $width = $originImage->getWidth(); |
||
54 | $height = $originImage->getHeight(); |
||
55 | |||
56 | $locator = new BinLocator('convert'); |
||
57 | |||
58 | $process = $locator->getProcess([ |
||
59 | $inputFile->getPathname(), |
||
60 | '-matte -virtual-pixel black -distort Perspective', |
||
61 | sprintf( |
||
62 | "'%s,%s 0,0 %s,%s %s,0 %s,%s %s,%s %s,%s 0,%s' %s", |
||
63 | $coordinates[0], |
||
64 | $coordinates[1], |
||
65 | $coordinates[2], |
||
66 | $coordinates[3], |
||
67 | $width, |
||
68 | $coordinates[4], |
||
69 | $coordinates[5], |
||
70 | $width, |
||
71 | $height, |
||
72 | $coordinates[6], |
||
73 | $coordinates[7], |
||
74 | $height, |
||
75 | $outputFilepathname |
||
76 | ), |
||
77 | ]); |
||
78 | |||
79 | $process->run(); |
||
80 | |||
81 | if (!$process->isSuccessful()) { |
||
82 | throw new ProcessFailedException($process); |
||
83 | } |
||
84 | |||
85 | //just to delete file after process |
||
86 | $tempfile = new FileTempObject($outputFilepathname); |
||
87 | |||
88 | return Image::fromFile($tempfile); |
||
89 | } |
||
91 |