From 47c157654fc662d0fbb858648eb261e5c4f1ee2a Mon Sep 17 00:00:00 2001 From: Todd Burry Date: Tue, 3 Sep 2019 21:41:47 -0400 Subject: [PATCH] Add pslam and fixes --- .circleci/config.yml | 3 ++- psalm.xml | 55 ++++++++++++++++++++++++++++++++++++++++++++ src/Transformer.php | 8 ++++--- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 psalm.xml diff --git a/.circleci/config.yml b/.circleci/config.yml index 80d95e4..3513206 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,9 +35,10 @@ jobs: php --version composer --version - run: - name: Test setup + name: Static Analysis command: | cd ~/workspace/repo + ./vendor/bin/psalm - run: name: PHPUnit Tests command: | diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..42f355b --- /dev/null +++ b/psalm.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Transformer.php b/src/Transformer.php index d273a57..f6dde8e 100644 --- a/src/Transformer.php +++ b/src/Transformer.php @@ -52,7 +52,7 @@ public function __invoke($data) { /** * Transform a spec node. * - * @param array|array $spec The spec node to transform. + * @param int|string|array $spec The spec node to transform. * @param array $data The data to transform. * @param array $root The root of the data from the first call to `transform()`. * @param string $path The current spec path being transformed. @@ -91,19 +91,21 @@ private function transformInternal($spec, $data, $root, string $path) { /** * Resolve a JSON reference. * - * @param string $ref The reference to resolve. + * @param int|string $ref The reference to resolve. * @param mixed $context The current data context to lookup. * @param mixed $root The root data context for absolute references. * @param bool $found Set to **true** if the reference was found or **false** otherwise. * @return mixed Returns the value at the reference. */ - private function resolveReference(string $ref, $context, $root, bool &$found = null) { + private function resolveReference($ref, $context, $root, bool &$found = null) { $found = true; if ($ref === '') { return $context; } elseif ($ref === '/') { return $root; + } elseif (is_int($ref)) { + return $context[$ref]; } elseif ($ref[0] === '/') { $ref = substr($ref, 1); $context = $root;