Skip to content

Commit

Permalink
Merge pull request #157 from bearsunday/spike
Browse files Browse the repository at this point in the history
Fix notice for array (string)
  • Loading branch information
koriym authored Apr 9, 2019
2 parents 12ef4e7 + 7ec9ac7 commit 4bea05e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
67 changes: 50 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
language: php
sudo: false

php:
- 7
- 7.1
- 7.2
- 7.3
- nightly

cache:
directories:
- vendor
- $HOME/.composer/cache
env:
matrix:
- DEPENDENCIES=""
- DEPENDENCIES="--prefer-lowest --prefer-stable"
before_script:
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then cp $HOME/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini /tmp; fi
- if [[ $TRAVIS_PHP_VERSION != '7.3' ]]; then phpenv config-rm xdebug.ini ; fi

matrix:
fast_finish: true

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- composer self-update
- composer update $DEPENDENCIES
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then composer require --dev phpstan/phpstan-shim ^0.9 friendsofphp/php-cs-fixer ^2.0 vimeo/psalm ^2.0; fi

install:
- composer update

script:
- ./vendor/bin/phpunit $COVERAGE;
- php demo/run.php
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then ./vendor/bin/php-cs-fixer --dry-run -v fix; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then ./vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then ./vendor/bin/psalm; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then phpenv config-add /tmp/xdebug.ini; ./vendor/bin/phpunit --coverage-clover=coverage.clover; else ./vendor/bin/phpunit; fi
after_script:
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- ./vendor/bin/phpunit;

jobs:
include:
- stage: Test
name: Lowest dependencies
php: 7.2
install: composer update --prefer-dist --prefer-lowest

- stage: Test
name: Code coverage
php: 7.2
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
script:
- ./vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml
after_script:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover;

- stage: Code Quality
name: Static analysis
php: 7.2
install: composer global require --dev phpstan/phpstan-shim ^0.9 vimeo/psalm ^2.0;
script:
- ~/.composer/vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction;
- ~/.composer/vendor/bin/psalm --show-info=false

- stage: Code Quality
name: Coding standards
php: 7.2
install: composer global require --dev friendsofphp/php-cs-fixer ^2.0;
script:
- ~/.composer/vendor/bin/php-cs-fixer --dry-run -v fix;

allow_failures:
- php: nightly
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"bear/cs": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.2"
"phpunit/phpunit": "^6.2",
"vimeo/psalm": "^2.0",
"phpstan/phpstan-shim": "^0.9"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 4 additions & 1 deletion src/Interceptor/JsonSchemaInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
use BEAR\Resource\Exception\JsonSchemaException;
use BEAR\Resource\Exception\JsonSchemaNotFoundException;
use BEAR\Resource\ResourceObject;
use function is_string;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use Ray\Aop\ReflectionMethod;
use Ray\Aop\WeavedInterface;
use Ray\Di\Di\Named;
use function is_string;

final class JsonSchemaInterceptor implements MethodInterceptor
{
Expand Down Expand Up @@ -108,6 +108,9 @@ private function getSchemaFile(JsonSchema $jsonSchema, ResourceObject $ro) : str
if (! $jsonSchema->schema) {
// for BC only
$ref = new \ReflectionClass($ro);
if (! $ref instanceof \ReflectionClass) {
throw new \ReflectionException(get_class($ro)); // @codeCoverageIgnore
}
$roFileName = $ro instanceof WeavedInterface ? $roFileName = $ref->getParentClass()->getFileName() : $ref->getFileName();
$bcFile = str_replace('.php', '.json', $roFileName);
if (file_exists($bcFile)) {
Expand Down
10 changes: 10 additions & 0 deletions src/NullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ public function __construct()

public function withQuery(array $query) : RequestInterface
{
unset($query);

return $this;
}

public function addQuery(array $query) : RequestInterface
{
unset($query);

return $this;
}

Expand All @@ -39,16 +43,22 @@ public function toUriWithMethod() : string

public function linkSelf(string $linkKey) : RequestInterface
{
unset($linkKey);

return $this;
}

public function linkNew(string $linkKey) : RequestInterface
{
unset($linkKey);

return $this;
}

public function linkCrawl(string $linkKey) : RequestInterface
{
unset($linkKey);

return $this;
}
}
3 changes: 2 additions & 1 deletion src/OptionsMethodRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private function paramDefault(array $paramDoc, \ReflectionParameter $parameter)
{
$hasDefault = $parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() !== null;
if ($hasDefault) {
$paramDoc[$parameter->name]['default'] = (string) $parameter->getDefaultValue();
$default = $parameter->getDefaultValue();
$paramDoc[$parameter->name]['default'] = is_array($default) ? '[]' : (string) $parameter->getDefaultValue();
}

return $paramDoc;
Expand Down

0 comments on commit 4bea05e

Please sign in to comment.