コード例 #1
0
ファイル: Transport.php プロジェクト: prgtw/basecrm-php-api
 /**
  * @param ResponseInterface $response
  * @param string            $key
  *
  * @throws RepresentationErrorException on 422 response
  * @throws ClientException on 4xx errors
  * @throws ServerException on 5xx errors
  * @throws BadResponseException when key is not found in response data
  * @return array|bool
  */
 private function processResponse(ResponseInterface $response, $key = null)
 {
     $status = $response->getStatusCode();
     if (204 == $status) {
         return true;
     }
     $decoded = $response->json();
     $decoded = Convert::objectToArray($decoded);
     if (422 == $status) {
         //@codeCoverageIgnoreStart
         throw new RepresentationErrorException('', $this->client->getLastRequest(), $response);
         //@codeCoverageIgnoreEnd
     }
     if (200 <= $status && 300 > $status) {
         $this->lastResponse = $response;
         if (null === $key) {
             return $decoded;
         }
         if (false === array_key_exists($key, $decoded)) {
             //@codeCoverageIgnoreStart
             $message = sprintf('Key "%s" not found in data', $key);
             throw new BadResponseException($message, $this->client->getLastRequest(), $response);
             //@codeCoverageIgnoreEnd
         }
         return $decoded[$key];
     }
     //@codeCoverageIgnoreStart
     throw BadResponseException::create($this->client->getLastRequest(), $response);
     //@codeCoverageIgnoreEnd
 }
コード例 #2
0
ファイル: ConvertTest.php プロジェクト: prgtw/basecrm-php-api
 /**
  * @dataProvider provideObjectsAndArrays
  *
  * @param object $object
  * @param array  $array
  */
 public function testObjectToArray($object, array $array)
 {
     $converted = Convert::objectToArray($object);
     $this->assertEquals($array, $converted);
 }