From 62639f9ce44d6e453cd3be3e962ebf7090e17563 Mon Sep 17 00:00:00 2001 From: chadicus Date: Sat, 8 Oct 2016 18:21:32 -0400 Subject: [PATCH] Switch to Chadicus coding standard --- .scrutinizer.yml | 20 +++++++-------- CONTRIBUTING.md | 17 ++++++++----- composer.json | 2 +- composer.lock | 41 ++++++++++++++++++++++++++++-- src/Adapter/AdapterInterface.php | 6 ++--- src/Cache/AbstractCache.php | 15 ++++++----- src/Cache/MongoCache.php | 2 +- src/Client.php | 4 +-- src/DataContainer.php | 7 +++-- src/DataContainerInterface.php | 3 +++ src/DataWrapper.php | 5 +++- src/DataWrapperInterface.php | 3 +++ src/Entities/AbstractEntity.php | 25 ++++++++++++------ src/Entities/Character.php | 2 +- src/Entities/Creator.php | 4 +-- src/Entities/EntityInterface.php | 13 ++++++---- src/Entities/Event.php | 2 +- src/Entities/TextObject.php | 2 +- src/Filterer.php | 7 +++++ tests/Adapter/CurlAdapterTest.php | 1 - tests/Assets/CollectionAdapter.php | 1 - tests/ClientTest.php | 2 -- tests/CollectionTest.php | 1 - tests/Entities/PriceTest.php | 4 +-- tests/Entities/SimpleEntity.php | 10 ++++++-- 25 files changed, 138 insertions(+), 61 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index a0f3e03..caee566 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -2,26 +2,26 @@ filter: excluded_paths: - 'vendor/*' - 'tests/*' - - 'examples/*' before_commands: - 'composer install --prefer-source' +checks: + php: + custom_coding_standard: + git_repository: 'https://github.com/chadicus/coding-standard' + git_version: '971fac1625463a72df0034fbfdd263561f2ccb4f' + ruleset_path: 'Chadicus/ruleset.xml' tools: php_analyzer: true php_mess_detector: true - php_code_sniffer: - config: - standard: PSR2 sensiolabs_security_checker: true php_loc: excluded_dirs: - vendor - tests - - examples php_pdepend: true php_sim: true build_failure_conditions: - - 'elements.rating(<= D).new.exists' # No new classes/methods with a rating of D or worse allowed (useful for legacy code) - - 'issues.label("coding-style").new.exists' # No new coding style issues allowed - - 'issues.label("coding-style").new.count > 5' # More than 5 new coding style issues. - - 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity - - 'project.metric("scrutinizer.quality", < 6)' # Code Quality Rating drops below 6 + - 'elements.rating(<= C).new.exists' + - 'issues.label("coding-style").new.exists' + - 'issues.severity(>= MAJOR).new.exists' + - 'project.metric("scrutinizer.quality", < 6)' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9fdddbc..adbcb29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,17 +1,22 @@ -## Questions and Bug Reports +# Contribution Guidelines +You are welcome to report [issues](/../../issues) or submit [pull requests](/../../pulls). While the below guidelines are necessary to get code merged, you can submit pull requests that do not adhere to them and I will try to take care of them in my spare time. If you can make sure the build is passing 100%, that would be very useful. -Submit via [GitHub Issues](https://github.com/chadicus/marvel-api-client/issues) +I recommend including details of your particular usecase(s) with any issues or pull requests. -## Pull Requests +## Questions and Bug Reports +Submit via [GitHub Issues](/../../issues). -Code changes should be sent through [GitHub Pull Requests](https://github.com/chadicus/marvel-api-client/pulls). Before submitting the pull request, make sure that phpunit reports success: +## Pull Requests +Code changes should be sent through [GitHub Pull Requests](/../../pulls). Before submitting the pull request, make sure that phpunit reports success: ```sh ./vendor/bin/phpunit --coverage-html coverage ``` -This build enforces 100% [PHPUnit](http://www.phpunit.de) code coverage and 0 errors for the [coding standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) +While the build does not enforce 100% [PHPUnit](http://www.phpunit.de) code coverage, it will not allow coverage to drop below its current percentage. + +The build will also not allow any errors for the [coding standard](http://chadicus.github.io/coding-standard/) ```sh -./vendor/bin/phpcs --standard=PSR2 src tests +./vendor/bin/phpcs --standard=./vendor/chadicus/coding-standard/Chadicus src tests ``` diff --git a/composer.json b/composer.json index 76e12a0..e8f1bf1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpunit/phpunit": "^5.5", "satooshi/php-coveralls": "^1.0", - "squizlabs/php_codesniffer": "^2.0", + "chadicus/coding-standard": "^1.1", "chadicus/test-helpers": "^1.0", "mongodb/mongodb": "^1.0" }, diff --git a/composer.lock b/composer.lock index 80ac5e3..73f14e6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a855e24b30331c7ccc7b6d50921adcee", - "content-hash": "2683e1641e0106795b5ed1feca981768", + "hash": "878f17ed8c2e13756d4fd483be194e0a", + "content-hash": "523d352fdd04fe76a227872511cdfe43", "packages": [ { "name": "chadicus/spl-exceptions", @@ -504,6 +504,43 @@ } ], "packages-dev": [ + { + "name": "chadicus/coding-standard", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/chadicus/coding-standard.git", + "reference": "3264851a30a7305995998660ee239d1a3d1c311f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chadicus/coding-standard/zipball/3264851a30a7305995998660ee239d1a3d1c311f", + "reference": "3264851a30a7305995998660ee239d1a3d1c311f", + "shasum": "" + }, + "require": { + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chad Gray", + "email": "chadwickgray@gmail.com", + "role": "Developer" + } + ], + "description": "Chadicus Coding standard", + "keywords": [ + "coding", + "phpcs", + "standard" + ], + "time": "2016-08-04 18:59:29" + }, { "name": "chadicus/test-helpers", "version": "v1.0.1", diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 982eab5..a909eb4 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -2,7 +2,7 @@ namespace Chadicus\Marvel\Api\Adapter; -use Chadicus\Marvel\Api; +use Chadicus\Marvel\Api\RequestInterface; /** * Simple interface for a client adapter. @@ -14,7 +14,7 @@ interface AdapterInterface * * @param RequestInterface $request The request to send. * - * @return Api\ResponseInterface + * @return \Chadicus\Marvel\Api\ResponseInterface */ - public function send(Api\RequestInterface $request); + public function send(RequestInterface $request); } diff --git a/src/Cache/AbstractCache.php b/src/Cache/AbstractCache.php index 9d2177c..fa5e771 100644 --- a/src/Cache/AbstractCache.php +++ b/src/Cache/AbstractCache.php @@ -2,6 +2,9 @@ namespace Chadicus\Marvel\Api\Cache; +/** + * Base class for all cache objects. + */ abstract class AbstractCache implements CacheInterface { /** @@ -14,7 +17,7 @@ abstract class AbstractCache implements CacheInterface /** * Sets the default time to live in seconds. * - * @param integer $defaultTimeToLive The time in seconds + * @param integer $defaultTimeToLive The time in seconds. * * @return void */ @@ -26,7 +29,7 @@ final public function setDefaultTTL($defaultTimeToLive) /** * Returns the default time to live in seconds. * - * @return integer The time in seconds + * @return integer The time in seconds. */ final public function getDefaultTTL() { @@ -34,13 +37,13 @@ final public function getDefaultTTL() } /** - * Helper method to check TTL value + * Helper method to check TTL value. * - * @param integer $ttl The time value to check in seconds + * @param integer $ttl The time value to check in seconds. * - * @return integer The valid $ttl value + * @return integer The valid $ttl value. * - * @throws \InvalidArgumentException Thrown if $ttl is < 1 or > CacheInterface::MAX_TTL + * @throws \InvalidArgumentException Thrown if $ttl is < 1 or > CacheInterface::MAX_TTL. */ final protected static function ensureTTL($ttl) { diff --git a/src/Cache/MongoCache.php b/src/Cache/MongoCache.php index f1c7b89..eb98d8f 100644 --- a/src/Cache/MongoCache.php +++ b/src/Cache/MongoCache.php @@ -39,7 +39,7 @@ public function __construct(Collection $collection, $defaultTimeToLive = CacheIn * * @param RequestInterface $request The request for which the response will be cached. * @param ResponseInterface $response The reponse to cache. - * @param integer $timeToLive The time in seconds that the cache should live. + * @param integer $timeToLive The time in seconds that the cache should live. * * @return void * diff --git a/src/Client.php b/src/Client.php index 479e79e..35dda4e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -157,8 +157,8 @@ final private function getFromCache(RequestInterface $request) /** * Allow calls such as $client->characters(); * - * @param string $name The name of the api resource - * @param array $arguments The parameters to pass to get() or search() + * @param string $name The name of the api resource. + * @param array $arguments The parameters to pass to get() or search(). * * @return Collection|EntityInterface */ diff --git a/src/DataContainer.php b/src/DataContainer.php index d82018b..59508f1 100644 --- a/src/DataContainer.php +++ b/src/DataContainer.php @@ -4,6 +4,9 @@ use DominionEnterprises\Util; +/** + * Object representation of the API result data container. + */ class DataContainer implements DataContainerInterface { /** @@ -44,7 +47,7 @@ class DataContainer implements DataContainerInterface /** * Create a new DataContainer instance. * - * @param array $input The data for the DataContainer + * @param array $input The data for the DataContainer. */ public function __construct(array $input) { @@ -69,7 +72,7 @@ public function __construct(array $input) /** * Helper method to derive the filter to use for the given resource array * - * @param mixed $results the results array from the API + * @param mixed $results The results array from the API. * * @return callable The filter to use */ diff --git a/src/DataContainerInterface.php b/src/DataContainerInterface.php index 194f606..82f2159 100644 --- a/src/DataContainerInterface.php +++ b/src/DataContainerInterface.php @@ -2,6 +2,9 @@ namespace Chadicus\Marvel\Api; +/** + * Interface for api data container which displays pagination information and an array of results returned by an API call. + */ interface DataContainerInterface { diff --git a/src/DataWrapper.php b/src/DataWrapper.php index 071c665..d058d32 100644 --- a/src/DataWrapper.php +++ b/src/DataWrapper.php @@ -4,6 +4,9 @@ use DominionEnterprises\Util; +/** + * Object representation of the API result data wrapper. + */ class DataWrapper implements DataWrapperInterface { /** @@ -58,7 +61,7 @@ class DataWrapper implements DataWrapperInterface /** * Create a new DataWrapper instance. * - * @param array $input The data for the DataWrapper + * @param array $input The data for the DataWrapper. */ public function __construct(array $input) { diff --git a/src/DataWrapperInterface.php b/src/DataWrapperInterface.php index 06b379c..de040eb 100644 --- a/src/DataWrapperInterface.php +++ b/src/DataWrapperInterface.php @@ -2,6 +2,9 @@ namespace Chadicus\Marvel\Api; +/** + * Interface for an API data wrapper which contains metadata about the call and a container object, + */ interface DataWrapperInterface { /** diff --git a/src/Entities/AbstractEntity.php b/src/Entities/AbstractEntity.php index 844f709..676c3e5 100644 --- a/src/Entities/AbstractEntity.php +++ b/src/Entities/AbstractEntity.php @@ -7,6 +7,9 @@ use Chadicus\Spl\Exceptions\NotAllowedException; use DominionEnterprises\Util; +/** + * Base entity class. + */ abstract class AbstractEntity implements EntityInterface, \ArrayAccess { /** @@ -17,9 +20,9 @@ abstract class AbstractEntity implements EntityInterface, \ArrayAccess private $data = []; /** - * Create a new AbstractEntity based on the given $input array + * Create a new AbstractEntity based on the given $input array. * - * @param array $input The data for the EntityInterface + * @param array $input The data for the EntityInterface. */ public function __construct(array $input = []) { @@ -32,11 +35,13 @@ public function __construct(array $input = []) } /** - * Get an AbstractEntity property + * Get an AbstractEntity property. * - * @param string $name The name of the property + * @param string $name The name of the property. * * @return mixed + * + * @throws UndefinedPropertyException Throw if this class does not contain the $name'd property. */ final public function __get($name) { @@ -51,12 +56,12 @@ final public function __get($name) /** * Allows for getX() method calls. * - * @param string $name The name of the method being called. + * @param string $name The name of the method being called. * @param array $arguments The arguments being passed to the method. This parameter is unused. * * @return mixed * - * @throws \BadMethodCallException Thrown if the property being accessed does not exist + * @throws \BadMethodCallException Thrown if the property being accessed does not exist. */ final public function __call($name, array $arguments = []) { @@ -97,7 +102,7 @@ final public static function fromArrays(array $inputs) /** * Create a new AbstractEntity based on the given $input array * - * @param array $input The data for the AbstractEntity + * @param array $input The data for the AbstractEntity. * * @return AbstractEntity */ @@ -134,9 +139,11 @@ final public function offsetGet($offset) * Sets the value at the specified index to newval * * @param string $offset The index being get. - * @param mixed $value The new value for the index + * @param mixed $value The new value for the index. * * @return void + * + * @throws NotAllowedException Ensure this object is immutable. */ final public function offsetSet($offset, $value) { @@ -150,6 +157,8 @@ final public function offsetSet($offset, $value) * @param string $offset The index being unset. * * @return void + * + * @throws NotAllowedException Ensure this object is immutable. */ final public function offsetUnset($offset) { diff --git a/src/Entities/Character.php b/src/Entities/Character.php index bdbad1b..3be5265 100644 --- a/src/Entities/Character.php +++ b/src/Entities/Character.php @@ -19,7 +19,7 @@ * @property-read ResourceList $stories A resource list of stories in which this character appears. * @property-read ResourceList $events A resource list of events in which this character appears. * @property-read ResourceList $series A resource list of series in which this character appears. -*/ + */ class Character extends AbstractEntity { /** diff --git a/src/Entities/Creator.php b/src/Entities/Creator.php index 0f7b8bd..2b13fb7 100644 --- a/src/Entities/Creator.php +++ b/src/Entities/Creator.php @@ -20,11 +20,11 @@ * @property-read ResourceList $stories A resource list containing the stories which feature work by this creator. * @property-read ResourceList $comics A resource list containing the comics which feature work by this creator. * @property-read ResourceList $events A resource list containing the events which feature work by this creator. -*/ + */ class Creator extends AbstractEntity { /** - * @see AbstractEntity::getFilters() + * @see AbstractEntity::getFilters(). * * @return array */ diff --git a/src/Entities/EntityInterface.php b/src/Entities/EntityInterface.php index b5a2be3..61437c1 100644 --- a/src/Entities/EntityInterface.php +++ b/src/Entities/EntityInterface.php @@ -2,17 +2,20 @@ namespace Chadicus\Marvel\Api\Entities; +/** + * Basic interface for all API entities. + */ interface EntityInterface { /** - * Create a new AbstractEntity based on the given $input array + * Create a new AbstractEntity based on the given $input array. * - * @param array $input The data for the EntityInterface + * @param array $input The data for the EntityInterface. */ public function __construct(array $input); /** - * Create an array of new AbstractEntity based on the given $input arrays + * Create an array of new AbstractEntity based on the given $input arrays. * * @param array[] $inputs The value to be filtered. * @@ -21,9 +24,9 @@ public function __construct(array $input); public static function fromArrays(array $inputs); /** - * Create a new AbstractEntity based on the given $input array + * Create a new AbstractEntity based on the given $input array. * - * @param array $input The data for the AbstractEntity + * @param array $input The data for the AbstractEntity. * * @return EntityInterface */ diff --git a/src/Entities/Event.php b/src/Entities/Event.php index 79ece9f..d63e43a 100644 --- a/src/Entities/Event.php +++ b/src/Entities/Event.php @@ -21,7 +21,7 @@ * @property-read ResourceList $creators A resource list containing creators whose work appears in this event. * @property-read Summary $next A summary representation of the event which follows this event. * @property-read Summary $previous A summary representation of the event which preceded this event. -*/ + */ class Event extends AbstractEntity { /** diff --git a/src/Entities/TextObject.php b/src/Entities/TextObject.php index 8526b1b..f2bc892 100644 --- a/src/Entities/TextObject.php +++ b/src/Entities/TextObject.php @@ -8,7 +8,7 @@ * @property-read string $type The string description of the text object (e.g. solicit text, preview text, etc.). * @property-read string $language A language code denoting which language the text object is written in. * @property-read string $text The text of the text object. -*/ + */ class TextObject extends AbstractEntity { /** diff --git a/src/Filterer.php b/src/Filterer.php index 1c1cee2..7bc459d 100644 --- a/src/Filterer.php +++ b/src/Filterer.php @@ -4,11 +4,18 @@ use DominionEnterprises\Filterer as BaseFilterer; +/** + * Custom filterer for sanitizing API result data. + */ abstract class Filterer { /** * @see \DominionEntepries\Filterer::filter(). * + * @param array $spec The filter specification. + * @param array $input The data to be filtered. + * @param array $options Array of filterer options. + * * @return array */ final public static function filter(array $spec, array $input, array $options = []) diff --git a/tests/Adapter/CurlAdapterTest.php b/tests/Adapter/CurlAdapterTest.php index d435320..3f9e99b 100644 --- a/tests/Adapter/CurlAdapterTest.php +++ b/tests/Adapter/CurlAdapterTest.php @@ -153,7 +153,6 @@ function ($curl, $option) { (new CurlAdapter())->send(new Request('not under test', 'get', ['foo' => 'bar'], [])); $this->assertSame(['Expect:', 'foo: bar'], $actualHeaders); - } /** diff --git a/tests/Assets/CollectionAdapter.php b/tests/Assets/CollectionAdapter.php index 97e5333..513259b 100644 --- a/tests/Assets/CollectionAdapter.php +++ b/tests/Assets/CollectionAdapter.php @@ -52,6 +52,5 @@ public function send(RequestInterface $request) ], ] ); - } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index e59999e..0d5ccbc 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -51,7 +51,6 @@ function () { $this->assertSame('GET', $request->getMethod()); $this->assertSame($expectedUrl, $request->getUrl()); - } /** @@ -156,7 +155,6 @@ function () { $this->assertSame('GET', $request->getMethod()); $this->assertSame($expectedUrl, $request->getUrl()); - } /** diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index 4452b79..cc5668c 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -235,7 +235,6 @@ public function multiIteration() } $this->assertSame(5, $iterations); - } /** diff --git a/tests/Entities/PriceTest.php b/tests/Entities/PriceTest.php index df7bef7..17fa19a 100644 --- a/tests/Entities/PriceTest.php +++ b/tests/Entities/PriceTest.php @@ -12,7 +12,7 @@ final class PriceTest extends \PHPUnit_Framework_TestCase /** * Verify invalid constructor parameters cause exceptions. * - * @param mixed $type The description of the price. + * @param mixed $type The description of the price. * @param mixed $price The price of the price. * * @test @@ -44,7 +44,7 @@ public function constructorBadData() /** * Verify valid constructor parameters cause no exceptions. * - * @param mixed $type The description of the price. + * @param mixed $type The description of the price. * @param mixed $price The price of the price. * * @test diff --git a/tests/Entities/SimpleEntity.php b/tests/Entities/SimpleEntity.php index 4eccf5a..5f51672 100644 --- a/tests/Entities/SimpleEntity.php +++ b/tests/Entities/SimpleEntity.php @@ -2,10 +2,16 @@ namespace Chadicus\Marvel\Api\Entities; +/** + * Entity objects for testing. + */ class SimpleEntity extends AbstractEntity { - public $input; - + /** + * @see AbstractEntity::getFilters(). + * + * @return array + */ protected function getFilters() { return ['field' => [['string']]];