From 814638c8aea96506dbedb0e6709e89aa08e8b3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20=C5=81akomski?= Date: Tue, 12 Dec 2017 09:18:43 +0100 Subject: [PATCH] Add phpstan and fix found errors --- .travis.yml | 12 ++++++++++++ README.md | 8 +++++--- composer.json | 4 ++-- src/AssocValue.php | 2 -- src/Filters.php | 6 +++--- src/PlainStringsArray.php | 11 +++++------ src/StringsArray.php | 4 ++-- 7 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d580645 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php + +php: + - 7.1 + - 7.2 + +install: + - composer install --dev + +script: + - ./bin/phpspec run + - ./bin/phpstan analyze -l 7 src diff --git a/README.md b/README.md index b20cdb7..92ca30e 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ GW/Values is a library to wrap PHP's primitive values into cleaner and more user-friendly objects. +[![Build Status](https://travis-ci.org/gowork/values.svg?branch=master)](https://travis-ci.org/gowork/values) + ## Installation -It works only on PHP 7.1. This library is available on Composer/Packagist as `gowork/values`. To install it execute: +It works on PHP >=7.1. This library is available on Composer/Packagist as `gowork/values`. To install it execute: ``` composer require gowork/values ^0.1 ``` @@ -21,7 +23,7 @@ and run `composer install` or `composer update` afterwards. If you are not using ## Usage -See [![here](docs/examples.md)] +See [here](./docs/examples.md) ## Contributing @@ -29,4 +31,4 @@ Want to contribute? Perfect! Submit an issue or Pull Request and explain what wo ## License -See LICENSE file in the main directory of this repository. +MIT license. See LICENSE file in the main directory of this repository. diff --git a/composer.json b/composer.json index 47c24e3..31dac54 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "php": "^7.1" }, "require-dev": { - "phpspec/phpspec": "^3.2" + "phpspec/phpspec": "^4.2", + "phpstan/phpstan": "^0.9" }, "autoload": { "psr-4": { @@ -35,7 +36,6 @@ "doc\\GW\\Value\\": "examples/" } }, - "minimum-stability": "dev", "config": { "bin-dir": "bin" } diff --git a/src/AssocValue.php b/src/AssocValue.php index 6817c57..907f31c 100644 --- a/src/AssocValue.php +++ b/src/AssocValue.php @@ -106,13 +106,11 @@ public function sortKeys(callable $comparator); public function with(string $key, $value); /** - * @param string $key * @return AssocValue */ public function without(string ...$keys); /** - * @param string $key * @return AssocValue */ public function only(string ...$keys); diff --git a/src/Filters.php b/src/Filters.php index f408a5c..583f0a0 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -25,8 +25,8 @@ public static function type(string $type): \Closure return $callable($value); } - if (is_object($value)) { - return get_class($value) === $type; + if (\is_object($value)) { + return \get_class($value) === $type; } return false; @@ -55,7 +55,7 @@ public static function notType(string $type): \Closure public static function notTypes(string ...$types): \Closure { - return self::not(self::types($types)); + return self::not(self::types(...$types)); } public static function not(callable $filter): \Closure diff --git a/src/PlainStringsArray.php b/src/PlainStringsArray.php index d928401..bbd73af 100644 --- a/src/PlainStringsArray.php +++ b/src/PlainStringsArray.php @@ -76,7 +76,7 @@ public function hasElement($element): bool { $stringValue = $element instanceof StringValue ? $element : Wrap::string($element); - return in_array($stringValue, $this->strings->toArray(), false); + return \in_array($stringValue, $this->strings->toArray(), false); } public function each(callable $callback): PlainStringsArray @@ -88,7 +88,6 @@ public function each(callable $callback): PlainStringsArray /** * @param callable|null $comparator function(mixed $valueA, mixed $valueB): int{-1, 0, 1} - * @return Collection */ public function unique(?callable $comparator = null): PlainStringsArray { @@ -142,12 +141,12 @@ public function offsetGet($offset): StringValue return $this->strings->offsetGet($offset); } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->strings->offsetSet($offset, $value); } - public function offsetUnset($offset) + public function offsetUnset($offset): void { $this->strings->offsetUnset($offset); } @@ -367,7 +366,7 @@ public function isEmpty(): bool } /** - * @return ArrayValue + * @return ArrayValue ArrayValue */ public function toArrayValue(): ArrayValue { @@ -375,7 +374,7 @@ public function toArrayValue(): ArrayValue } /** - * @return AssocValue + * @return AssocValue AssocValue */ public function toAssocValue(): AssocValue { diff --git a/src/StringsArray.php b/src/StringsArray.php index d0d0b70..313a0b6 100644 --- a/src/StringsArray.php +++ b/src/StringsArray.php @@ -262,12 +262,12 @@ public function postfix(StringValue $other); public function prefix(StringValue $other); /** - * @return ArrayValue + * @return ArrayValue ArrayValue */ public function toArrayValue(): ArrayValue; /** - * @return AssocValue + * @return AssocValue AssocValue */ public function toAssocValue(): AssocValue; }