| Conditions | 14 | 
| Paths | 113 | 
| Total Lines | 86 | 
| Code Lines | 59 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 6 | ||
| 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  | 
            ||
| 67 | public function write(Cfp $cfp, $source)  | 
            ||
| 68 |     { | 
            ||
| 69 |         try { | 
            ||
| 70 | $uri = '';  | 
            ||
| 71 | $this->client->get($cfp->conferenceUri, [  | 
            ||
| 72 |                 'on_stats' => function (TransferStats $stats) use (&$uri) { | 
            ||
| 73 | $uri = (string) $stats->getEffectiveUri();  | 
            ||
| 74 | }  | 
            ||
| 75 | ]);  | 
            ||
| 76 |         } catch (\Exception $e) { | 
            ||
| 77 |             throw new \InvalidArgumentException('Event-URI could not be verified: ' . $e->getMessage()); | 
            ||
| 78 | }  | 
            ||
| 79 | $cfp->conferenceUri = $uri;  | 
            ||
| 80 | |||
| 81 | $body = [  | 
            ||
| 82 | 'name' => $cfp->conferenceName,  | 
            ||
| 83 |             'dateCfpEnd'     => $cfp->dateEnd->format('c'), | 
            ||
| 84 |             'dateEventStart' => $cfp->eventStartDate->format('c'), | 
            ||
| 85 |             'dateEventEnd'   => $cfp->eventEndDate->format('c'), | 
            ||
| 86 | 'timezone' => $cfp->timezone,  | 
            ||
| 87 | 'uri' => $cfp->uri,  | 
            ||
| 88 | 'eventUri' => $cfp->conferenceUri,  | 
            ||
| 89 | 'iconUri' => $cfp->iconUri,  | 
            ||
| 90 | 'description' => $cfp->description,  | 
            ||
| 91 | 'location' => $cfp->location,  | 
            ||
| 92 | 'latitude' => $cfp->latitude,  | 
            ||
| 93 | 'longitude' => $cfp->longitude,  | 
            ||
| 94 | 'tags' => $cfp->tags,  | 
            ||
| 95 | 'source' => $source,  | 
            ||
| 96 | ];  | 
            ||
| 97 | |||
| 98 |         if ($cfp->dateStart instanceof \DateTimeInterface) { | 
            ||
| 99 |             $body['dateCfpStart'] = $cfp->dateStart->format('c'); | 
            ||
| 100 | }  | 
            ||
| 101 | |||
| 102 |         try { | 
            ||
| 103 |             $this->client->request('GET', sprintf( | 
            ||
| 104 | $this->baseUri . '/%1$s',  | 
            ||
| 105 | sha1($cfp->conferenceUri)  | 
            ||
| 106 | ), []);  | 
            ||
| 107 | $exists = true;  | 
            ||
| 108 |         } catch (BadResponseException $e) { | 
            ||
| 109 | $exists = false;  | 
            ||
| 110 | }  | 
            ||
| 111 | |||
| 112 |         try { | 
            ||
| 113 |             if ($exists === false) { | 
            ||
| 114 | // Doesn't exist, so create it  | 
            ||
| 115 |                 $response = $this->client->request('POST', sprintf( | 
            ||
| 116 | $this->baseUri  | 
            ||
| 117 | ), [  | 
            ||
| 118 | 'headers' => [  | 
            ||
| 119 | 'Authorization' => 'Bearer ' . $this->bearerToken,  | 
            ||
| 120 | ],  | 
            ||
| 121 | 'form_params' => $body  | 
            ||
| 122 | ]);  | 
            ||
| 123 |             } else { | 
            ||
| 124 | // Exists, so update it  | 
            ||
| 125 |                 $response = $this->client->request('PUT', sprintf( | 
            ||
| 126 | $this->baseUri . '/%1$s',  | 
            ||
| 127 | sha1($cfp->conferenceUri)  | 
            ||
| 128 | ), [  | 
            ||
| 129 | 'headers' => [  | 
            ||
| 130 | 'Authorization' => 'Bearer ' . $this->bearerToken,  | 
            ||
| 131 | ],  | 
            ||
| 132 | 'form_params' => $body  | 
            ||
| 133 | ]);  | 
            ||
| 134 | }  | 
            ||
| 135 |         } catch (BadResponseException $e) { | 
            ||
| 136 | $this->output->writeln($e->getMessage());  | 
            ||
| 137 | return $e->getMessage();  | 
            ||
| 138 |         } catch (\Exception $e) { | 
            ||
| 139 | $this->output->writeln($e->getMessage());  | 
            ||
| 140 | return $e->getMessage();  | 
            ||
| 141 | }  | 
            ||
| 142 | |||
| 143 |         if ($response && ($response->getStatusCode() === 200 || $response->getStatusCode() === 201)) { | 
            ||
| 144 | $this->output->writeln(sprintf(  | 
            ||
| 145 | 'Conference "%1$s" succcessfully %2$s.',  | 
            ||
| 146 | $cfp->conferenceName,  | 
            ||
| 147 | ($exists) ? 'updated' : 'created'  | 
            ||
| 148 | ));  | 
            ||
| 149 | }  | 
            ||
| 150 | |||
| 151 | return (isset($response) && ($response->getStatusCode() === 200 || $response->getStatusCode() === 201))?'Success':'Failure';  | 
            ||
| 152 | }  | 
            ||
| 153 | |||
| 159 |