| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 26 |
| 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 |
||
| 77 | public function publish(Ad $ad, Platform $platform): int |
||
| 78 | { |
||
| 79 | $this->authenticate($platform); |
||
| 80 | |||
| 81 | // Select 'Other' category |
||
| 82 | /* @var $crawler Crawler */ |
||
| 83 | $crawler = Goutte::request('GET', self::CATEGORY_URL); |
||
| 84 | |||
| 85 | // Add information about the add (title, description, price, ...) |
||
| 86 | /* @var $form \Form */ |
||
| 87 | $form = $crawler->selectButton('Continuer >')->form(); |
||
| 88 | $adParameters = array_merge($form->getValues(), $ad->toArray()); |
||
|
|
|||
| 89 | $crawler = Goutte::submit($form, $adParameters); |
||
| 90 | |||
| 91 | $errors = []; |
||
| 92 | $crawler->filter('.fem.fieldwarning')->each(function ($node) use (&$errors) { |
||
| 93 | $errors[] = $node->text(); |
||
| 94 | }); |
||
| 95 | |||
| 96 | if (count($errors) > 0) { |
||
| 97 | throw new \Exception(implode(', ', $errors)); |
||
| 98 | } |
||
| 99 | |||
| 100 | // Get image from url |
||
| 101 | $this->imageUrlValidation($ad->img_url); |
||
| 102 | $file = file_get_contents($ad->img_url); |
||
| 103 | $name = $this->getUniqueNameFromUrl($ad->img_url); |
||
| 104 | Storage::put($name, $file); |
||
| 105 | $this->imageSizeValidation($name); |
||
| 106 | |||
| 107 | // Add image |
||
| 108 | $form = $crawler->filter('#imageuploader')->first()->form(); |
||
| 109 | $form['picture'] = Storage::path($name); |
||
| 110 | $crawler = Goutte::submit($form); |
||
| 111 | |||
| 112 | // Remove it since we don't need it anymore |
||
| 113 | Storage::delete($name); |
||
| 114 | |||
| 115 | // Accept added image(s) |
||
| 116 | $form = $crawler->selectButton('Continuer >')->form(); |
||
| 117 | $crawler = Goutte::submit($form, $form->getValues()); |
||
| 118 | |||
| 119 | // Select free plan |
||
| 120 | $form = $crawler->selectButton('Choisir')->form(); |
||
| 121 | $crawler = Goutte::submit($form, ['classic' => 'Choisir']); |
||
| 122 | |||
| 123 | // Confirm |
||
| 124 | $form = $crawler->selectButton('Insérer mon annonce >')->form(); |
||
| 125 | $crawler = Goutte::submit($form); |
||
| 126 | |||
| 127 | return $this->getPublicationItemIdFromUrl($crawler->getUri()); |
||
| 128 | } |
||
| 159 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.