diff --git a/bin/swagger b/bin/swagger index 0e02853a3..ecaa50483 100755 --- a/bin/swagger +++ b/bin/swagger @@ -127,7 +127,7 @@ set_error_handler(function ($errno, $errstr, $file, $line) use ($errorTypes) { if (!(error_reporting() & $errno)) { return; // This error code is not included in error_reporting } - $type = @$errorTypes[$errno] ?: 'ERROR'; + $type = array_key_exists($errno, $errorTypes) ?: 'ERROR'; error_log('[' . $type . '] '.$errstr .' in '.$file.' on line '.$line); if ($type === 'ERROR') { exit($errno); diff --git a/src/Analysis.php b/src/Analysis.php index ff8465977..b8ae981c9 100644 --- a/src/Analysis.php +++ b/src/Analysis.php @@ -51,6 +51,7 @@ class Analysis /** * @param array $annotations + * @param null $context */ public function __construct($annotations = [], $context = null) { @@ -153,12 +154,12 @@ public function getSubClasses($class) public function getSuperClasses($class) { - $classDefinition = @$this->classes[$class]; + $classDefinition = isset($this->classes[$class]) ? $this->classes[$class] : null; if (!$classDefinition || empty($classDefinition['extends'])) { // unknown class, or no inheritance? return []; } $extends = $classDefinition['extends']; - $extendsDefinition = @$this->classes[$extends]; + $extendsDefinition = isset($this->classes[$extends]) ? $this->classes[$extends] : null; if (!$extendsDefinition) { return []; } diff --git a/src/Context.php b/src/Context.php index 554f57076..065b16e1f 100644 --- a/src/Context.php +++ b/src/Context.php @@ -251,7 +251,7 @@ public static function detect($index = 0) if (isset($position['line'])) { $context->line = $position['line']; } - $caller = @$backtrace[$index + 1]; + $caller = isset($backtrace[$index + 1]) ? $backtrace[$index + 1] : null; if (isset($caller['function'])) { $context->method = $caller['function']; if (isset($caller['type']) && $caller['type'] === '::') { diff --git a/src/Processors/AugmentProperties.php b/src/Processors/AugmentProperties.php index d41e8b3d3..61b69ea4d 100644 --- a/src/Processors/AugmentProperties.php +++ b/src/Processors/AugmentProperties.php @@ -71,7 +71,8 @@ public function __invoke(Analysis $analysis) } $property->type = $type; } elseif ($property->ref === null && $typeMatches[2] === '') { - $property->ref = @$refs[strtolower($context->fullyQualifiedName($type))]; + $tmpKey = strtolower($context->fullyQualifiedName($type)); + $property->ref = array_key_exists($tmpKey, $refs) ? $refs[$tmpKey] : null; } if ($typeMatches[2] === '[]') { if ($property->items === null) { @@ -80,7 +81,8 @@ public function __invoke(Analysis $analysis) '_context' => new Context(['generated' => true], $context) ]); if ($property->items->type === null) { - $property->items->ref = @$refs[strtolower($context->fullyQualifiedName($type))]; + $tmpKey = strtolower($context->fullyQualifiedName($type)); + $property->items->ref = array_key_exists($tmpKey, $refs) ? $refs[$tmpKey] : null; } } $property->type = 'array'; diff --git a/src/functions.php b/src/functions.php index 95b68debe..1e2c7359b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -30,10 +30,10 @@ */ function scan($directory, $options = array()) { - $analyser = @$options['analyser'] ?: new StaticAnalyser(); - $analysis = @$options['analysis'] ?: new Analysis(); - $processors = @$options['processors'] ?: Analysis::processors(); - $exclude = @$options['exclude'] ?: null; + $analyser = array_key_exists('analyser', $options) ? new StaticAnalyser() : null; + $analysis = array_key_exists('analysis', $options) ? new Analysis() : null; + $processors = array_key_exists('processors', $options) ? Analysis::processors() : null; + $exclude = array_key_exists('exclude', $options) ? $options['exclude'] : null; // Crawl directory and parse all files $finder = Util::finder($directory, $exclude); diff --git a/tests/SwaggerTestCase.php b/tests/SwaggerTestCase.php index c767ea41e..8c5438629 100644 --- a/tests/SwaggerTestCase.php +++ b/tests/SwaggerTestCase.php @@ -187,7 +187,7 @@ protected function sorted(stdClass $object, $origin = 'unknown') if (gettype($value[0]) === 'string') { $sortFn = 'strcasecmp'; } else { - $sortFn = @$sortMap[$property]; + $sortFn = isset($sortMap[$property]) ? $sortMap[$property] : null; } if ($sortFn) { usort($value, $sortFn);