diff --git a/src/ApiDefinition.php b/src/ApiDefinition.php index 9c93217d..cc2d28a8 100644 --- a/src/ApiDefinition.php +++ b/src/ApiDefinition.php @@ -22,8 +22,15 @@ */ class ApiDefinition implements ArrayInstantiationInterface { - /* public */ const PROTOCOL_HTTP = 'HTTP'; - /* public */ const PROTOCOL_HTTPS = 'HTTPS'; + /** + * @var string + */ + const PROTOCOL_HTTP = 'HTTP'; + + /** + * @var string + */ + const PROTOCOL_HTTPS = 'HTTPS'; /** * The API Title (required) @@ -365,7 +372,7 @@ public function getResourceByPath($path) */ public function getResourcesAsUri(RouteFormatterInterface $formatter = null) { - if (!$formatter) { + if ($formatter === null) { $formatter = new NoRouteFormatter(); } @@ -818,10 +825,6 @@ private function setProtocolsFromBaseUri() { $schema = strtoupper(parse_url($this->baseUri, PHP_URL_SCHEME)); - if (empty($schema)) { - $this->protocols = [self::PROTOCOL_HTTPS, self::PROTOCOL_HTTP]; - } else { - $this->protocols = [$schema]; - } + $this->protocols = empty($schema) ? [self::PROTOCOL_HTTPS, self::PROTOCOL_HTTP] : [$schema]; } } diff --git a/src/Method.php b/src/Method.php index e9e16ab1..7a195008 100644 --- a/src/Method.php +++ b/src/Method.php @@ -137,11 +137,7 @@ public static function createFromArray($method, array $data = [], ApiDefinition if (isset($data['body'])) { foreach ($data['body'] as $key => $bodyData) { if (is_array($bodyData)) { - if (in_array($key, WebFormBody::$validMediaTypes, true)) { - $body = WebFormBody::createFromArray($key, $bodyData); - } else { - $body = Body::createFromArray($key, $bodyData); - } + $body = in_array($key, WebFormBody::$validMediaTypes, true) ? WebFormBody::createFromArray($key, $bodyData) : Body::createFromArray($key, $bodyData); $method->addBody($body); } @@ -346,7 +342,7 @@ public function addProtocol($protocol) throw new \InvalidArgumentException(sprintf('"%s" is not a valid protocol', $protocol)); } - if (in_array($protocol, $this->protocols, true) === false) { + if (!in_array($protocol, $this->protocols, true)) { $this->protocols[] = $protocol; } } @@ -500,7 +496,7 @@ public function addSecurityScheme(SecurityScheme $securityScheme, $merge = true) assert($body instanceof WebFormBody); $params = $body->getParameters(); - foreach ($params as $parameterName => $namedParameter) { + foreach ($params as $namedParameter) { $body->addParameter($namedParameter); } } diff --git a/src/NamedParameter.php b/src/NamedParameter.php index 3220bc44..08b674cf 100644 --- a/src/NamedParameter.php +++ b/src/NamedParameter.php @@ -11,31 +11,103 @@ class NamedParameter implements ArrayInstantiationInterface { // Type constants + /** + * @var string + */ const TYPE_STRING = 'string'; + /** + * @var string + */ const TYPE_NUMBER = 'number'; + /** + * @var string + */ const TYPE_INTEGER = 'integer'; + /** + * @var string + */ const TYPE_DATE = 'date'; + /** + * @var string + */ const TYPE_BOOLEAN = 'boolean'; + /** + * @var string + */ const TYPE_FILE = 'file'; + /** + * @var string + */ const TYPE_DATE_ONLY = 'date-only'; + /** + * @var string + */ const TYPE_TIME_ONLY = 'time-only'; + /** + * @var string + */ const TYPE_DATETIME_ONLY = 'datetime-only'; + /** + * @var string + */ const TYPE_DATETIME = 'datetime'; + /** + * @var string + */ const TYPE_ARRAY = 'array'; // Validation exception codes + /** + * @var int + */ const VAL_NOTBOOLEAN = 1; + /** + * @var int + */ const VAL_NOTDATE = 2; + /** + * @var int + */ const VAL_NOTSTRING = 3; + /** + * @var int + */ const VAL_NOTINT = 4; + /** + * @var int + */ const VAL_NOTNUMBER = 5; + /** + * @var int + */ const VAL_NOTFILE = 6; // Unused + /** + * @var int + */ const VAL_ISREQUIRED = 7; + /** + * @var int + */ const VAL_TOOSHORT = 8; + /** + * @var int + */ const VAL_TOOLONG = 9; + /** + * @var int + */ const VAL_NUMLESSTHAN = 10; + /** + * @var int + */ const VAL_GREATERTHAN = 11; + /** + * @var int + */ const VAL_PATTERNFAIL = 12; + /** + * @var int + */ const VAL_NOTENUMVALUE = 13; /** @@ -736,7 +808,7 @@ public function validate($param) case static::TYPE_DATE: // Must be a valid date - if (\DateTime::createFromFormat('D, d M Y H:i:s T', $param) === false) { + if (!\DateTime::createFromFormat('D, d M Y H:i:s T', $param)) { throw new ValidationException($this->getKey() . ' is not a valid date', static::VAL_NOTDATE); } @@ -927,11 +999,7 @@ public function getMatchPattern() break; case self::TYPE_STRING: - if ($this->getMinLength() || $this->getMaxLength()) { - $pattern = '((?!\/).){' . $this->getMinLength() . ',' . $this->getMaxLength() . '}'; - } else { - $pattern = '([^/]+)'; - } + $pattern = $this->getMinLength() || $this->getMaxLength() ? '((?!\/).){' . $this->getMinLength() . ',' . $this->getMaxLength() . '}' : '([^/]+)'; break; default: diff --git a/src/Parser.php b/src/Parser.php index 87d51918..ecbfa0df 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -331,7 +331,7 @@ private function replaceSchemas($array, $schemas) */ private function recurseAndParseSchemas(array $array, $rootDir) { - foreach ($array as $key => &$value) { + foreach ($array as &$value) { if (is_array($value)) { if (isset($value['schema'])) { $fileDir = $this->getCachedFilePath($value['schema']); @@ -385,12 +385,7 @@ private function parseSecuritySettings($schemesArray) $securitySchemes = []; foreach ($schemesArray as $key => $securitySchemeData) { - // Create the default parser. - if (isset($this->securitySettingsParsers['*'])) { - $parser = $this->securitySettingsParsers['*']; - } else { - $parser = false; - } + $parser = isset($this->securitySettingsParsers['*']) ? $this->securitySettingsParsers['*'] : false; $securitySchemes[$key] = $securitySchemeData; $securityScheme = $securitySchemes[$key]; @@ -431,8 +426,8 @@ private function parseResourceTypes($ramlData) } foreach ($ramlData as $key => $value) { - if (strpos($key, '/') === 0) { - $name = (isset($value['displayName'])) ? $value['displayName'] : substr($key, 1); + if (mb_strpos($key, '/') === 0) { + $name = (isset($value['displayName'])) ? $value['displayName'] : mb_substr($key, 1); $ramlData[$key] = $this->replaceTypes($value, $keyedResourceTypes, $key, $name, $key); } } @@ -504,19 +499,15 @@ private function addNamespacePrefix($nameSpace, array $definition) } } else { if (!in_array($item, ApiDefinition::getStraightForwardTypes(), true)) { - if (mb_strpos($item, '|') !== false) { - $definition[$key] = implode( - '|', - array_map( - function ($v) use ($nameSpace) { - return $nameSpace . '.' . trim($v); - }, - explode('|', $item) - ) - ); - } else { - $definition[$key] = $nameSpace . '.' . $item; - } + $definition[$key] = mb_strpos($item, '|') !== false ? implode( + '|', + array_map( + function ($v) use ($nameSpace) { + return $nameSpace . '.' . trim($v); + }, + explode('|', $item) + ) + ) : $nameSpace . '.' . $item; } } } elseif (is_array($definition[$key])) { @@ -624,12 +615,12 @@ private function loadAndParseFile($fileName, $rootDir) $rootDir = realpath($rootDir); $fullPath = realpath($rootDir . '/' . $fileName); - if (is_readable($fullPath) === false) { + if (!is_readable($fullPath)) { throw new FileNotFoundException($fileName); } } else { $fullPath = $rootDir . '/' . $fileName; - if (filter_var($fullPath, FILTER_VALIDATE_URL) === false && is_readable($fullPath) === false) { + if (!filter_var($fullPath, FILTER_VALIDATE_URL) && !is_readable($fullPath)) { throw new FileNotFoundException($fileName); } } @@ -660,11 +651,7 @@ private function loadAndParseFile($fileName, $rootDir) ); $fileData = $this->includeAndParseFiles($fileData, $rootDir); } else { - if (in_array($fileExtension, array_keys($this->fileLoaders), true)) { - $loader = $this->fileLoaders[$fileExtension]; - } else { - $loader = $this->fileLoaders['*']; - } + $loader = array_key_exists($fileExtension, $this->fileLoaders) ? $this->fileLoaders[$fileExtension] : $this->fileLoaders['*']; $fileData = $loader->loadFile($fullPath); $this->cachedFilesPaths[md5($fileData)] = $fullPath; @@ -800,11 +787,7 @@ private function replaceTypes($raml, $types, $path, $name, $parentKey = null) } $newValue = $this->replaceTypes($value, $types, $path, $newName, $key); - if (isset($newArray[$key]) && is_array($newArray[$key])) { - $newArray[$key] = array_replace_recursive($newArray[$key], $newValue); - } else { - $newArray[$key] = $newValue; - } + $newArray[$key] = isset($newArray[$key]) && is_array($newArray[$key]) ? array_replace_recursive($newArray[$key], $newValue) : $newValue; } } diff --git a/src/Response.php b/src/Response.php index 2f94e9a1..fa73aeba 100644 --- a/src/Response.php +++ b/src/Response.php @@ -55,7 +55,7 @@ class Response implements ArrayInstantiationInterface, MessageSchemaInterface */ public function __construct($statusCode) { - $this->statusCode = (int) $statusCode; + $this->statusCode = $statusCode; $this->bodyList = []; $this->headers = []; } diff --git a/src/SecurityScheme/SecuritySchemeDescribedBy.php b/src/SecurityScheme/SecuritySchemeDescribedBy.php index 761f780d..909035a6 100644 --- a/src/SecurityScheme/SecuritySchemeDescribedBy.php +++ b/src/SecurityScheme/SecuritySchemeDescribedBy.php @@ -14,13 +14,6 @@ */ class SecuritySchemeDescribedBy implements ArrayInstantiationInterface { - /** - * The key of the security scheme - * - * @var string - */ - private $key; - /** * A list of non default headers (optional) * @@ -29,7 +22,6 @@ class SecuritySchemeDescribedBy implements ArrayInstantiationInterface * @var NamedParameter[] */ private $headers = []; - /** * List of query parameters supported by this method * @@ -38,14 +30,12 @@ class SecuritySchemeDescribedBy implements ArrayInstantiationInterface * @var NamedParameter[] */ private $queryParameters = []; - /** * A list of possible responses from this method * * @var Response[] */ private $responses = []; - /** * A list of the bodies of this method * @@ -53,16 +43,6 @@ class SecuritySchemeDescribedBy implements ArrayInstantiationInterface */ private $bodyList = []; - /** - * Create a new security scheme description - * - * @param string $key - */ - public function __construct($key) - { - $this->key = $key; - } - /** * Create a new SecuritySchemeDescribedBy from an array of data * @@ -82,11 +62,7 @@ public static function createFromArray($key, array $data = []) if (isset($data['body'])) { foreach ($data['body'] as $key => $bodyData) { - if (in_array($key, \Raml\WebFormBody::$validMediaTypes, true)) { - $body = \Raml\WebFormBody::createFromArray($key, $bodyData); - } else { - $body = \Raml\Body::createFromArray($key, $bodyData); - } + $body = in_array($key, \Raml\WebFormBody::$validMediaTypes, true) ? \Raml\WebFormBody::createFromArray($key, $bodyData) : \Raml\Body::createFromArray($key, $bodyData); $describedBy->addBody($body); } diff --git a/src/SecurityScheme/SecuritySettings/DefaultSecuritySettings.php b/src/SecurityScheme/SecuritySettings/DefaultSecuritySettings.php index e7f9104a..e5d8cfc3 100644 --- a/src/SecurityScheme/SecuritySettings/DefaultSecuritySettings.php +++ b/src/SecurityScheme/SecuritySettings/DefaultSecuritySettings.php @@ -8,6 +8,8 @@ class DefaultSecuritySettings implements SecuritySettingsInterface, \ArrayAccess { /** * Supports all types + * + * @var string */ const TYPE = '*'; @@ -21,7 +23,7 @@ class DefaultSecuritySettings implements SecuritySettingsInterface, \ArrayAccess /** * Flesh out the settings * - * @param array $data + * @param array $data * @param SecuritySettingsInterface $sourceSettings * * @throws \Exception diff --git a/src/SecurityScheme/SecuritySettings/OAuth1SecuritySettings.php b/src/SecurityScheme/SecuritySettings/OAuth1SecuritySettings.php index 78255e3f..379457a4 100644 --- a/src/SecurityScheme/SecuritySettings/OAuth1SecuritySettings.php +++ b/src/SecurityScheme/SecuritySettings/OAuth1SecuritySettings.php @@ -6,6 +6,9 @@ class OAuth1SecuritySettings implements SecuritySettingsInterface { + /** + * @var string + */ const TYPE = 'OAuth 1.0'; /** diff --git a/src/SecurityScheme/SecuritySettings/OAuth2SecuritySettings.php b/src/SecurityScheme/SecuritySettings/OAuth2SecuritySettings.php index 4e11bb55..6c108d55 100644 --- a/src/SecurityScheme/SecuritySettings/OAuth2SecuritySettings.php +++ b/src/SecurityScheme/SecuritySettings/OAuth2SecuritySettings.php @@ -6,6 +6,9 @@ class OAuth2SecuritySettings implements SecuritySettingsInterface { + /** + * @var string + */ const TYPE = 'OAuth 2.0'; // -- diff --git a/src/TraitCollection.php b/src/TraitCollection.php index d0faa785..002c891a 100644 --- a/src/TraitCollection.php +++ b/src/TraitCollection.php @@ -15,7 +15,7 @@ class TraitCollection implements \Iterator * * @var self */ - private static $instance = null; + private static $instance; /** * Collection @@ -23,7 +23,6 @@ class TraitCollection implements \Iterator * @var TraitDefinition[] */ private $collection = []; - /** * Current position * @@ -32,9 +31,9 @@ class TraitCollection implements \Iterator private $position = 0; /** - * prevent initiation from outside, there can be only one! - * - */ + * prevent initiation from outside, there can be only one! + * + */ private function __construct() { $this->collection = []; @@ -101,7 +100,7 @@ public function valid() */ public function add(TraitDefinition $traitToAdd) { - foreach ($this->collection as $key => $trait) { + foreach ($this->collection as $trait) { if ($trait === $traitToAdd) { throw new Exception(sprintf('Trait already exists %s', var_export($traitToAdd, true))); } diff --git a/src/TypeCollection.php b/src/TypeCollection.php index 82ef9062..2a334a63 100644 --- a/src/TypeCollection.php +++ b/src/TypeCollection.php @@ -22,14 +22,12 @@ class TypeCollection implements \Iterator * @var TypeInterface[] */ private $collection = []; - /** * Current position * * @var string */ private $position = 0; - /** * Types which need to inherit properties from their parent * @@ -37,13 +35,6 @@ class TypeCollection implements \Iterator */ private $typesWithInheritance = []; - /** - * Singleton, prevent initiation from outside, there can be only one! - */ - private function __construct() - { - } - /** * @return self */ @@ -163,7 +154,7 @@ public function hasTypeByName($name) */ public function applyInheritance() { - foreach ($this->typesWithInheritance as $key => $type) { + foreach ($this->typesWithInheritance as $type) { $type->inheritFromParent(); } // now clear list to prevent applying multiple times on the same objects diff --git a/src/Types/DateOnlyType.php b/src/Types/DateOnlyType.php index 4494349e..622b9036 100644 --- a/src/Types/DateOnlyType.php +++ b/src/Types/DateOnlyType.php @@ -12,6 +12,9 @@ */ class DateOnlyType extends Type { + /** + * @var string + */ const FORMAT = 'Y-m-d'; /** diff --git a/src/Types/DatetimeOnlyType.php b/src/Types/DatetimeOnlyType.php index cad33238..25dc7429 100644 --- a/src/Types/DatetimeOnlyType.php +++ b/src/Types/DatetimeOnlyType.php @@ -10,6 +10,9 @@ */ class DatetimeOnlyType extends Type { + /** + * @var string + */ const FORMAT = "Y-m-d\TH:i:s"; /** diff --git a/src/Types/DatetimeType.php b/src/Types/DatetimeType.php index 67ac96a2..ec5c9b16 100644 --- a/src/Types/DatetimeType.php +++ b/src/Types/DatetimeType.php @@ -10,6 +10,9 @@ */ class DatetimeType extends Type { + /** + * @var string + */ const DEFAULT_FORMAT = DATE_RFC3339; /** @@ -32,11 +35,8 @@ public static function createFromArray($name, array $data = []) assert($type instanceof self); foreach ($data as $key => $value) { - switch ($key) { - case 'format': - $type->setFormat($value); - - break; + if ($key === 'format') { + $type->setFormat($value); } } @@ -46,7 +46,7 @@ public static function createFromArray($name, array $data = []) /** * Get the value of Format * - * @return mixed + * @return string */ public function getFormat() { @@ -56,7 +56,7 @@ public function getFormat() /** * Set the value of Format * - * @param mixed $format + * @param string $format * * @return self */ diff --git a/src/Types/NumberType.php b/src/Types/NumberType.php index b94b7e43..01a3a9e9 100644 --- a/src/Types/NumberType.php +++ b/src/Types/NumberType.php @@ -192,25 +192,25 @@ public function validate($value) } switch ($this->format) { case 'int8': - if (filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -128, 'max_range' => 127]]) === false) { + if (!filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -128, 'max_range' => 127]])) { $this->errors[] = TypeValidationError::unexpectedValueType($this->getName(), 'int8', $value); } break; case 'int16': - if (filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -32768, 'max_range' => 32767]]) === false) { + if (!filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -32768, 'max_range' => 32767]])) { $this->errors[] = TypeValidationError::unexpectedValueType($this->getName(), 'int16', $value); } break; case 'int32': - if (filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -2147483648, 'max_range' => 2147483647]]) === false) { + if (!filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -2147483648, 'max_range' => 2147483647]])) { $this->errors[] = TypeValidationError::unexpectedValueType($this->getName(), 'int32', $value); } break; case 'int64': - if (filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -9223372036854775808, 'max_range' => 9223372036854775807]]) === false) { + if (!filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -9223372036854775808, 'max_range' => 9223372036854775807]])) { $this->errors[] = TypeValidationError::unexpectedValueType($this->getName(), 'int64', $value); } diff --git a/src/Types/ObjectType.php b/src/Types/ObjectType.php index 91e1cfcc..b1f74d76 100644 --- a/src/Types/ObjectType.php +++ b/src/Types/ObjectType.php @@ -113,11 +113,7 @@ public function discriminate($value) { if (isset($value[$this->getDiscriminator()])) { if ($this->getDiscriminatorValue() !== null) { - if ($this->getDiscriminatorValue() === $value[$this->getDiscriminator()]) { - return true; - } - - return false; + return $this->getDiscriminatorValue() === $value[$this->getDiscriminator()]; } return $value[$this->getDiscriminator()] === $this->getName(); @@ -145,7 +141,7 @@ public function getProperties() public function setProperties(array $properties) { foreach ($properties as $name => $property) { - if ($property instanceof Type === false) { + if (!$property instanceof Type) { $property = ApiDefinition::determineType($name, $property); } $this->properties[] = $property; @@ -189,7 +185,7 @@ public function getMinProperties() */ public function setMinProperties($minProperties) { - $this->minProperties = (int) $minProperties; + $this->minProperties = $minProperties; return $this; } @@ -212,7 +208,7 @@ public function getMaxProperties() */ public function setMaxProperties($maxProperties) { - $this->maxProperties = (int) $maxProperties; + $this->maxProperties = $maxProperties; return $this; } @@ -308,8 +304,8 @@ public function validate($value) } foreach ($value as $name => $propertyValue) { $property = $this->getPropertyByName($name); - if (!$property) { - if ($this->additionalProperties === false) { + if ($property === null) { + if (!$this->additionalProperties) { $this->errors[] = TypeValidationError::unexpectedProperty($name); } diff --git a/src/Types/TimeOnlyType.php b/src/Types/TimeOnlyType.php index a00617b1..74abcad3 100644 --- a/src/Types/TimeOnlyType.php +++ b/src/Types/TimeOnlyType.php @@ -10,6 +10,9 @@ */ class TimeOnlyType extends Type { + /** + * @var string + */ const FORMAT = 'H:i:s'; /** diff --git a/src/Types/TypeValidationError.php b/src/Types/TypeValidationError.php index 8baa31f8..4d864825 100644 --- a/src/Types/TypeValidationError.php +++ b/src/Types/TypeValidationError.php @@ -226,9 +226,7 @@ public static function unionTypeValidationFailed($property, array $errorsGrouped $errors = []; foreach ($errorsGroupedByTypes as $type => $typeErrors) { $message = array_reduce($typeErrors, function ($acc, self $error) { - $acc .= (string) $error . ', '; - - return $acc; + return $acc . ((string) $error . ', '); }, "$type ("); diff --git a/src/Types/UnionType.php b/src/Types/UnionType.php index 3fc1448d..04604992 100644 --- a/src/Types/UnionType.php +++ b/src/Types/UnionType.php @@ -91,7 +91,7 @@ public function setPossibleTypes(array $possibleTypes) public function setProperties(array $properties) { foreach ($properties as $name => $property) { - if ($property instanceof Type === false) { + if (!$property instanceof Type) { $property = ApiDefinition::determineType($name, $property); } $this->properties[] = $property; @@ -177,8 +177,8 @@ public function validate($value) if (is_array($selfValue)) { foreach ($selfValue as $name => $propertyValue) { $property = $this->getPropertyByName($name); - if (!$property) { - if ($this->additionalProperties === false) { + if ($property === null) { + if (!$this->additionalProperties) { $errors[] = TypeValidationError::unexpectedProperty($name); } diff --git a/src/Utility/StringTransformer.php b/src/Utility/StringTransformer.php index 68c5a147..20f92fa2 100644 --- a/src/Utility/StringTransformer.php +++ b/src/Utility/StringTransformer.php @@ -4,13 +4,34 @@ class StringTransformer { + /** + * @var int + */ const LOWER_CAMEL_CASE = 1; + /** + * @var int + */ const LOWER_HYPHEN_CASE = 2; + /** + * @var int + */ const LOWER_UNDERSCORE_CASE = 4; + /** + * @var int + */ const UPPER_CAMEL_CASE = 8; + /** + * @var int + */ const UPPER_HYPHEN_CASE = 16; + /** + * @var int + */ const UPPER_UNDERSCORE_CASE = 32; + /** + * @var string[] + */ private static $possibleTransformations = [ self::LOWER_CAMEL_CASE, self::LOWER_HYPHEN_CASE, diff --git a/src/Utility/TraitParserHelper.php b/src/Utility/TraitParserHelper.php index 13dd7ee1..a382d542 100644 --- a/src/Utility/TraitParserHelper.php +++ b/src/Utility/TraitParserHelper.php @@ -18,11 +18,7 @@ public static function applyVariables(array $values, array $traitDefinition) foreach ($traitDefinition as $key => &$value) { $newKey = static::applyFunctions($key, $values); - if (is_array($value)) { - $value = static::applyVariables($values, $value); - } else { - $value = static::applyFunctions($value, $values); - } + $value = is_array($value) ? static::applyVariables($values, $value) : static::applyFunctions($value, $values); $newTrait[$newKey] = $value; } diff --git a/src/Validator/ContentConverter.php b/src/Validator/ContentConverter.php index 4f8126dd..0b6ada3a 100644 --- a/src/Validator/ContentConverter.php +++ b/src/Validator/ContentConverter.php @@ -50,7 +50,7 @@ private static function parseMediaRange($mediaRange) { $parts = explode(';', $mediaRange); $params = []; - foreach ($parts as $i => $param) { + foreach ($parts as $param) { if (strpos($param, '=') !== false) { list($k, $v) = explode('=', trim($param)); $params[$k] = $v; @@ -65,11 +65,7 @@ private static function parseMediaRange($mediaRange) throw new \UnexpectedValueException('Malformed media-range: ' . $mediaRange); } $plusPos = strpos($subtype, '+'); - if (false !== $plusPos) { - $genericSubtype = substr($subtype, $plusPos + 1); - } else { - $genericSubtype = $subtype; - } + $genericSubtype = false !== $plusPos ? substr($subtype, $plusPos + 1) : $subtype; return sprintf('%s/%s', trim($type), trim($genericSubtype)); } diff --git a/tests/ApiDefinitionTest.php b/tests/ApiDefinitionTest.php index 0903e8d2..364a8852 100644 --- a/tests/ApiDefinitionTest.php +++ b/tests/ApiDefinitionTest.php @@ -60,7 +60,7 @@ public function shouldReturnFullResourcesForRamlFileWithNoFormatter() $api = $this->buildParser()->parse(__DIR__ . '/fixture/includeSchema.raml'); $noFormatter = new NoRouteFormatter(); - $routes = $api->getResourcesAsUri($noFormatter, $api->getResources()); + $routes = $api->getResourcesAsUri($noFormatter); $this->assertCount(4, $routes->getRoutes()); $this->assertEquals([ @@ -80,7 +80,7 @@ public function shouldReturnFullResourcesForRamlFileWithSymfonyFormatter() $routeCollection = new RouteCollection(); $routeFormatter = new SymfonyRouteFormatter($routeCollection); - $routes = $api->getResourcesAsUri($routeFormatter, $api->getResources()); + $routes = $api->getResourcesAsUri($routeFormatter); $this->assertEquals($routeFormatter, $routes); @@ -217,10 +217,10 @@ public function shouldParseComplexTypes() public function shouldPassValidResponse() { $api = $this->buildParser()->parse(__DIR__ . '/fixture/raml-1.0/complexTypes.raml'); + /** @var Body $body */ $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType( 'application/json' ); - /** @var Body $body */ $validResponse = '{ "onCall": { "firstname": "John", @@ -257,8 +257,8 @@ public function shouldPassValidResponse() public function shouldRejectMissingParameterResponse() { $api = $this->buildParser()->parse(__DIR__ . '/fixture/raml-1.0/complexTypes.raml'); - $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); /** @var Body $body */ + $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); $type = $body->getType(); $invalidResponse = [ @@ -287,8 +287,8 @@ public function shouldRejectMissingParameterResponse() public function shouldRejectInvalidIntegerParameterResponse() { $api = $this->buildParser()->parse(__DIR__ . '/fixture/raml-1.0/complexTypes.raml'); - $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); /** @var Body $body */ + $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); $type = $body->getType(); $invalidResponse = [ @@ -339,8 +339,8 @@ public function shouldRejectInvalidIntegerParameterResponse() public function shouldRejectInvalidStringParameterResponse() { $api = $this->buildParser()->parse(__DIR__ . '/fixture/raml-1.0/complexTypes.raml'); + /** @var Body $body */ $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); - /* @var $body Body */ $type = $body->getType(); $invalidResponse = [ @@ -391,8 +391,8 @@ public function shouldRejectInvalidStringParameterResponse() public function shouldRejectInvalidEnumParameterResponse() { $api = $this->buildParser()->parse(__DIR__ . '/fixture/raml-1.0/complexTypes.raml'); - $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); /** @var Body $body */ + $body = $api->getResourceByPath('/orgs/{orgId}')->getMethod('get')->getResponse(200)->getBodyByType('application/json'); $type = $body->getType(); $invalidResponse = [ diff --git a/tests/NamedParameters/ParameterTypesTest.php b/tests/NamedParameters/ParameterTypesTest.php index 39e3425f..6ae9be83 100644 --- a/tests/NamedParameters/ParameterTypesTest.php +++ b/tests/NamedParameters/ParameterTypesTest.php @@ -254,7 +254,7 @@ public function shouldValidateDate() */ public function shouldValidateDateOnly() { - $this->expectException('\Raml\Exception\ValidationException', 'Expected date-only'); + $this->expectException('\Raml\Exception\ValidationException'); $namedParameter = $this->validateBody->getParameter('date-only'); $namedParameter->validate('2018-08-05T13:24:55'); } @@ -264,7 +264,7 @@ public function shouldValidateDateOnly() */ public function shouldValidateDateTimeOnly() { - $this->expectException('\Raml\Exception\ValidationException', 'Expected datetime-only'); + $this->expectException('\Raml\Exception\ValidationException'); $namedParameter = $this->validateBody->getParameter('datetime-only'); $namedParameter->validate('2018-08-05T13:24:55+12:00'); } @@ -274,7 +274,7 @@ public function shouldValidateDateTimeOnly() */ public function shouldValidateTimeOnly() { - $this->expectException('\Raml\Exception\ValidationException', 'Expected time-only'); + $this->expectException('\Raml\Exception\ValidationException'); $namedParameter = $this->validateBody->getParameter('time-only'); $namedParameter->validate('2018-08-05T13:24:55'); } @@ -284,7 +284,7 @@ public function shouldValidateTimeOnly() */ public function shouldValidateDateTime() { - $this->expectException('\Raml\Exception\ValidationException', 'Expected datetime'); + $this->expectException('\Raml\Exception\ValidationException'); $namedParameter = $this->validateBody->getParameter('datetime'); $namedParameter->validate('2018-08-05 13:24:55'); } @@ -294,7 +294,7 @@ public function shouldValidateDateTime() */ public function shouldValidateDateTimeFormat() { - $this->expectException('\Raml\Exception\ValidationException', 'Expected datetime with format Y-m-d H:i:s'); + $this->expectException('\Raml\Exception\ValidationException'); $namedParameter = $this->validateBody->getParameter('datetime_format'); $namedParameter->validate('2018-08-05T13:24:55'); } diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 9ad71d5b..e4df06d3 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -413,8 +413,8 @@ public function shouldParseJsonIntoArray() $response = $method->getResponse(200); /** @var Body $body */ $body = $response->getBodyByType('application/json'); - $schema = $body->getSchema(); /** @var JsonSchemaDefinition $schema */ + $schema = $body->getSchema(); $schemaArray = $schema->getJsonArray(); $this->assertEquals('A canonical song', $schemaArray['items']['description']);