Skip to content

Commit

Permalink
changed @ operator as array_key_exists or isset for zircote#331
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci committed Sep 5, 2016
1 parent 84237b0 commit e4ebf82
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/swagger
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Analysis

/**
* @param array $annotations
* @param null $context
*/
public function __construct($annotations = [], $context = null)
{
Expand Down Expand Up @@ -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 [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] === '::') {
Expand Down
6 changes: 4 additions & 2 deletions src/Processors/AugmentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/SwaggerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e4ebf82

Please sign in to comment.