From b9e33bcbaaf3ca60829b7ee4989d150c22261f24 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 21:40:36 -0500 Subject: [PATCH 01/26] refactor: upgrade for cake4 --- .editorconfig | 8 +- .gitattributes | 5 +- .gitignore | 10 +- .scrutinizer.yml | 21 ++++ .travis.yml | 49 +++++--- CONTRIBUTING.md | 83 ++++++++++++++ composer.json | 107 +++++++++-------- phpstan-baseline.neon | 2 + phpstan.neon | 9 ++ phpunit.xml.dist | 3 +- psalm.xml | 29 +++++ src/Model/Behavior/TagBehavior.php | 10 +- src/Model/Entity/Tag.php | 3 +- src/Model/Entity/TagAwareTrait.php | 6 +- src/Model/Entity/Tagged.php | 2 + src/Model/Table/TaggedTable.php | 4 +- src/Model/Table/TagsTable.php | 7 +- src/Plugin.php | 19 +++ tests/Fixture/BunsFixture.php | 2 + tests/Fixture/MuffinsFixture.php | 2 + tests/Fixture/TaggedFixture.php | 2 + tests/Fixture/TagsFixture.php | 2 + .../Model/Behavior/TagBehaviorTest.php | 2 + .../Model/Entity/TagAwareTraitTest.php | 14 +-- tests/bootstrap.php | 108 +++++++++++++----- .../test_app/src/Model/Entity/TagsMuffin.php | 17 +++ 26 files changed, 401 insertions(+), 125 deletions(-) create mode 100644 .scrutinizer.yml create mode 100644 CONTRIBUTING.md create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon create mode 100644 psalm.xml create mode 100644 src/Plugin.php create mode 100644 tests/test_app/src/Model/Entity/TagsMuffin.php diff --git a/.editorconfig b/.editorconfig index a84f86c..bd0ddd7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,18 +1,16 @@ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org -root = true +root = false [*] indent_style = space indent_size = 4 +charset = "utf-8" end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.bat] -end_of_line = crlf - [*.yml] indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 17493ec..d912dbb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,11 @@ # Remove files for archives generated using `git archive` +CONTRIBUTING.md export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.semver export-ignore phpunit.xml.dist export-ignore .travis.yml export-ignore +.scrutinizer.yml export-ignore tests export-ignore +docs export-ignore +.github export-ignore diff --git a/.gitignore b/.gitignore index 364f9bd..5209c91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ -/composer.lock -/plugins -/vendor +*.pyc +docs/_build +phpunit.xml +vendor/ +composer.lock +tmp +.phpunit.result.cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..27146f7 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,21 @@ +imports: + - php + +filter: + excluded_paths: + - docs/ + - tests/ +tools: + php_mess_detector: true + php_cpd: + excluded_dirs: + - docs/ + - tests/ + php_loc: + excluded_dirs: + - docs/ + - tests/ + php_pdepend: + excluded_dirs: + 1: docs/ + 2: tests/ diff --git a/.travis.yml b/.travis.yml index 6fb2cd8..af10731 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 - 7.2 + - 7.3 + - 7.4 env: matrix: @@ -15,40 +14,52 @@ env: global: - DEFAULT=1 +services: + - mysql + - postgresql + matrix: fast_finish: true include: - - php: 7.1 + - php: 7.2 env: PHPCS=1 DEFAULT=0 - - php: 7.1 - env: PHPSTAN=1 DEFAULT=0 - - - php: 5.6 - env: PREFER_LOWEST=1 + - php: 7.2 + env: STATIC_ANALYSIS=1 DEFAULT=0 before_script: - - if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi - - if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction ; fi - - if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest ; fi + - if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi + - if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi - - if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi + - if [[ $DB = 'mysql' ]]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi - - if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer; fi - - if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi + - if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^4.0; fi + - if [[ $STATIC_ANALYSIS = 1 ]]; then composer require --dev phpstan/phpstan:^0.12 psalm/phar:^3.7; fi script: - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then + mkdir -p build/logs + vendor/bin/phpunit --coverage-clover=build/logs/clover.xml + fi + + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 5 src; fi + + - if [[ $STATIC_ANALYSIS = 1 ]]; then vendor/bin/phpstan.phar analyse src && vendor/bin/psalm.phar --show-info=false; fi after_success: - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then + wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar + chmod +x php-coveralls.phar + ./php-coveralls.phar + fi notifications: email: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0f198e2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,83 @@ +# How to contribute + +Tags loves to welcome your contributions. There are several ways to help out: +* Create a ticket in GitHub, if you have found a bug +* Write testcases for open bug tickets +* Write patches for open bug/feature tickets, preferably with testcases included +* Contribute to the [documentation](https://github.com/UseMuffin/Tags/tree/gh-pages) + +There are a few guidelines that we need contributors to follow so that we have a +chance of keeping on top of things. + +## Getting Started + +* Make sure you have a [GitHub account](https://github.com/signup/free) +* Submit a ticket for your issue, assuming one does not already exist. + * Clearly describe the issue including steps to reproduce when it is a bug. + * Make sure you fill in the earliest version that you know has the issue. +* Fork the repository on GitHub. + +## Making Changes + +* Create a topic branch from where you want to base your work. + * This is usually the develop branch + * To quickly create a topic branch based on master; `git branch + master/my_contribution master` then checkout the new branch with `git + checkout master/my_contribution`. Better avoid working directly on the + `master` branch, to avoid conflicts if you pull in updates from origin. +* Make commits of logical units. +* Check for unnecessary whitespace with `git diff --check` before committing. +* Use descriptive commit messages and reference the #ticket number +* Core testcases should continue to pass. You can run tests locally or enable + [travis-ci](https://travis-ci.org/) for your fork, so all tests and codesniffs + will be executed. +* Your work should apply the CakePHP coding standards. + +## Which branch to base the work + +* Bugfix branches will be based on develop branch. +* New features that are backwards compatible will be based on develop branch +* New features or other non-BC changes will go in the next major release branch. + +## Submitting Changes + +* Push your changes to a topic branch in your fork of the repository. +* Submit a pull request to the repository with the correct target branch. + +## Testcases and codesniffer + +Tags tests requires [PHPUnit](http://www.phpunit.de/manual/current/en/installation.html) +8.5.0 or higher. To run the testcases locally use the following command: + + phpunit + +To run the sniffs for CakePHP coding standards + + phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=docs src/ tests/ + +Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) +repository to setup the CakePHP standard. The README contains installation info +for the sniff and phpcs. + +## Documentation + +You can build the documentation using Docker via the following commands: + + # go to the docs dir + cd docs + + # build the docs + docker build . + + # make the html + docker run -it --rm -v $(pwd)/docs:/data UseMuffin/Tags make html + + # open the generated html docs in docs/_build/html + +# Additional Resources + +* [CakePHP coding standards](https://book.cakephp.org/4/en/contributing/cakephp-coding-conventions.html) +* [Bug tracker](https://github.com/UseMuffin/Tags/issues) +* [General GitHub documentation](https://help.github.com/) +* [GitHub pull request documentation](https://help.github.com/send-pull-requests/) +* #cakephp IRC channel on freenode.org diff --git a/composer.json b/composer.json index feef1a3..769450d 100644 --- a/composer.json +++ b/composer.json @@ -1,48 +1,61 @@ { - "name" : "muffin/tags", - "description" : "Tags plugin for CakePHP 3.x", - "type" : "cakephp-plugin", - "keywords" : [ - "cakephp", - "muffin", - "tags" - ], - "homepage" : "https://github.com/usemuffin/tags", - "license" : "MIT", - "authors" : [{ - "name" : "Jad Bitar", - "homepage" : "http://jadb.io", - "role" : "Author" - }, { - "name" : "ADmad", - "homepage" : "https://github.com/ADmad", - "role" : "Author" - }, { - "name" : "Others", - "homepage" : "https://github.com/usemuffin/tags/graphs/contributors" - } - ], - "support" : { - "issues" : "https://github.com/usemuffin/tags/issues", - "source" : "https://github.com/usemuffin/tags" - }, - "require" : { - "cakephp/orm" : "^3.5", - "cakephp/migrations" : "^2.0" - }, - "require-dev" : { - "cakephp/cakephp" : "^3.5", - "phpunit/phpunit" : "^5.7.14|^6.0", - "muffin/slug" : "^1.4" - }, - "autoload" : { - "psr-4" : { - "Muffin\\Tags\\" : "src" - } - }, - "autoload-dev" : { - "psr-4" : { - "Muffin\\Tags\\Test\\" : "tests" - } - } -} \ No newline at end of file + "name": "muffin/tags", + "description": "Tags plugin for CakePHP 3.x", + "type": "cakephp-plugin", + "keywords": [ + "cakephp", + "muffin", + "tags" + ], + "homepage": "https://github.com/usemuffin/tags", + "license": "MIT", + "authors": [ + { + "name": "Jad Bitar", + "homepage": "http://jadb.io", + "role": "Author" + }, + { + "name": "ADmad", + "homepage": "https://github.com/ADmad", + "role": "Author" + }, + { + "name": "Others", + "homepage": "https://github.com/usemuffin/tags/graphs/contributors" + } + ], + "support": { + "issues": "https://github.com/usemuffin/tags/issues", + "source": "https://github.com/usemuffin/tags" + }, + "require": { + "cakephp/orm": "^4.0", + "cakephp/migrations": "^3.0" + }, + "require-dev": { + "cakephp/cakephp": "^4.0", + "cakephp/cakephp-codesniffer": "^4.0", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "~8.5.0", + "psalm/phar": "^3.7" + }, + "suggest": { + "muffin/slug": "For adding slugs to tags" + }, + "autoload": { + "psr-4": { + "Muffin\\Tags\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Muffin\\Tags\\Test\\": "tests" + } + }, + "prefer-stable": true, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..f51e71c --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a61fda5 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 6 + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false + excludes_analyse: + - */src/TestSuite/* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 57c56ba..ef26a93 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ > - + ./tests/ @@ -25,6 +25,7 @@ ./src/ + ./src/ diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..15a7cd6 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index 73dcaa8..94047c2 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -1,4 +1,6 @@ bindAssociations(); $this->attachCounters(); @@ -65,7 +67,7 @@ public function initialize(array $config) * * @return array Events list. */ - public function implementedEvents() + public function implementedEvents(): array { return $this->getConfig('implementedEvents'); } @@ -233,7 +235,7 @@ public function normalizeTags($tags) $result[] = $common + ['id' => $existingTag]; continue; } - list($id, $label) = $this->_normalizeTag($tag); + [$id, $label] = $this->_normalizeTag($tag); $result[] = $common + compact(empty($id) ? $df : $pk) + [ 'tag_key' => $tagKey, ]; @@ -290,7 +292,7 @@ protected function _normalizeTag($tag) $label = $tag; $separator = $this->getConfig('separator'); if (strpos($tag, $separator) !== false) { - list($namespace, $label) = explode($separator, $tag); + [$namespace, $label] = explode($separator, $tag); } return [ diff --git a/src/Model/Entity/Tag.php b/src/Model/Entity/Tag.php index b798784..96a36d1 100644 --- a/src/Model/Entity/Tag.php +++ b/src/Model/Entity/Tag.php @@ -1,11 +1,12 @@ $tag) { - if ((empty($untag[$pk]) || $tag[$pk] === $untag[$pk]) && + if ( + (empty($untag[$pk]) || $tag[$pk] === $untag[$pk]) && (empty($untag[$df]) || $tag[$df] === $untag[$df]) ) { unset($tags[$k]); diff --git a/src/Model/Entity/Tagged.php b/src/Model/Entity/Tagged.php index 3ed3b5f..eb26044 100644 --- a/src/Model/Entity/Tagged.php +++ b/src/Model/Entity/Tagged.php @@ -1,4 +1,6 @@ setTable('tags_tagged'); $this->addBehavior('Timestamp'); diff --git a/src/Model/Table/TagsTable.php b/src/Model/Table/TagsTable.php index 8f2b849..64cf8c2 100644 --- a/src/Model/Table/TagsTable.php +++ b/src/Model/Table/TagsTable.php @@ -1,4 +1,6 @@ setTable('tags_tags'); $this->setDisplayField('label'); $this->addBehavior('Timestamp'); - if (Plugin::loaded('Muffin/Slug')) { + if (Plugin::isLoaded('Muffin/Slug')) { $this->addBehavior('Muffin/Slug.Slug'); } } diff --git a/src/Plugin.php b/src/Plugin.php new file mode 100644 index 0000000..80a0dfc --- /dev/null +++ b/src/Plugin.php @@ -0,0 +1,19 @@ + 'Muffin\Tags\Test\App', + 'encoding' => 'UTF-8', + 'fullBaseUrl' => 'http://localhost' +]); +Cake\Core\Configure::write('debug', true); + +$TMP = new \Cake\Filesystem\Folder(TMP); +$TMP->create(TMP . 'cache/models', 0777); +$TMP->create(TMP . 'cache/persistent', 0777); +$TMP->create(TMP . 'cache/views', 0777); + +$cache = [ + 'default' => [ + 'engine' => 'File' + ], + '_cake_core_' => [ + 'className' => 'File', + 'prefix' => 'muffin_tags_myapp_cake_core_', + 'path' => CACHE . 'persistent/', + 'serialize' => true, + 'duration' => '+10 seconds' + ], + '_cake_model_' => [ + 'className' => 'File', + 'prefix' => 'muffin_tags_my_app_cake_model_', + 'path' => CACHE . 'models/', + 'serialize' => 'File', + 'duration' => '+10 seconds' + ] +]; -chdir($root); -if (file_exists($root . '/config/bootstrap.php')) { - require $root . '/config/bootstrap.php'; +Cake\Cache\Cache::setConfig($cache); +Cake\Core\Configure::write('Session', [ + 'defaults' => 'php' +]); - return; +// Ensure default test connection is defined +if (!getenv('db_dsn')) { + putenv('db_dsn=sqlite:///:memory:'); } -require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; +Cake\Datasource\ConnectionManager::setConfig('test', [ + 'url' => getenv('db_dsn'), + 'timezone' => 'UTC' +]); -\Cake\Core\Plugin::load('Muffin/Tags', ['path' => dirname(dirname(__FILE__)) . DS]); +Plugin::getCollection()->add(new \Muffin\Tags\Plugin()); diff --git a/tests/test_app/src/Model/Entity/TagsMuffin.php b/tests/test_app/src/Model/Entity/TagsMuffin.php new file mode 100644 index 0000000..126d09c --- /dev/null +++ b/tests/test_app/src/Model/Entity/TagsMuffin.php @@ -0,0 +1,17 @@ + Date: Mon, 20 Jan 2020 22:03:19 -0500 Subject: [PATCH 02/26] fix: correct some test issues --- src/Model/Behavior/TagBehavior.php | 1 + .../Model/Behavior/TagBehaviorTest.php | 28 +++++++++---------- .../Model/Entity/TagAwareTraitTest.php | 8 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index 94047c2..bd19992 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -295,6 +295,7 @@ protected function _normalizeTag($tag) [$namespace, $label] = explode($separator, $tag); } + /** @psalm-suppress PossiblyNullArgument **/ return [ trim($namespace), trim($label), diff --git a/tests/TestCase/Model/Behavior/TagBehaviorTest.php b/tests/TestCase/Model/Behavior/TagBehaviorTest.php index aa4277c..4c1e104 100644 --- a/tests/TestCase/Model/Behavior/TagBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/TagBehaviorTest.php @@ -15,7 +15,7 @@ class TagBehaviorTest extends TestCase 'plugin.Muffin/Tags.Tags', ]; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -26,14 +26,14 @@ public function setUp() $this->Behavior = $table->behaviors()->Tag; } - public function tearDown() + public function tearDown(): void { parent::tearDown(); TableRegistry::getTableLocator()->clear(); unset($this->Behavior); } - public function testSavingDuplicates() + public function testSavingDuplicates(): void { $entity = $this->Table->newEntity([ 'name' => 'Duplicate Tags?', @@ -47,7 +47,7 @@ public function testSavingDuplicates() $this->assertEquals(1, $count); } - public function testDefaultInitialize() + public function testDefaultInitialize(): void { $belongsToMany = $this->Table->getAssociation('Tags'); $this->assertInstanceOf('Cake\ORM\Association\BelongsToMany', $belongsToMany); @@ -56,7 +56,7 @@ public function testDefaultInitialize() $this->AssertInstanceOf('Cake\ORM\Association\HasMany', $hasMany); } - public function testCustomInitialize() + public function testCustomInitialize(): void { $this->Table->removeBehavior('Tag'); $this->Table->addBehavior('Muffin/Tags.Tag', [ @@ -71,7 +71,7 @@ public function testCustomInitialize() $this->assertInstanceOf('Cake\ORM\Association\HasMany', $hasMany); } - public function testNormalizeTags() + public function testNormalizeTags(): void { $result = $this->Behavior->normalizeTags('foo, 3:foobar, bar'); $expected = [ @@ -132,7 +132,7 @@ public function testNormalizeTags() $this->assertEquals($expected, $result); } - public function testMarshalingOnlyNewTags() + public function testMarshalingOnlyNewTags(): void { $data = [ 'name' => 'Muffin', @@ -158,7 +158,7 @@ public function testMarshalingOnlyNewTags() $this->assertTrue($entity->isDirty('tags')); } - public function testMarshalingOnlyExistingTags() + public function testMarshalingOnlyExistingTags(): void { $data = [ 'name' => 'Muffin', @@ -184,7 +184,7 @@ public function testMarshalingOnlyExistingTags() $this->assertTrue($entity->isDirty('tags')); } - public function testMarshalingBothNewAndExistingTags() + public function testMarshalingBothNewAndExistingTags(): void { $data = [ 'name' => 'Muffin', @@ -197,7 +197,7 @@ public function testMarshalingBothNewAndExistingTags() $this->assertTrue($entity->isDirty('tags')); } - public function testMarshalingWithEmptyTagsString() + public function testMarshalingWithEmptyTagsString(): void { $data = [ 'name' => 'Muffin', @@ -208,7 +208,7 @@ public function testMarshalingWithEmptyTagsString() $this->assertNull($entity->get('tags')); } - public function testSaveIncrementsCounter() + public function testSaveIncrementsCounter(): void { $data = [ 'name' => 'Muffin', @@ -229,7 +229,7 @@ public function testSaveIncrementsCounter() $this->assertEquals($expected, $result); } - public function testCounterCacheDisabled() + public function testCounterCacheDisabled(): void { $this->Table->removeBehavior('Tag'); $this->Table->Tagged->removeBehavior('CounterCache'); @@ -256,7 +256,7 @@ public function testCounterCacheDisabled() * @expectedException \RuntimeException * @expectedExceptionMessage Field "non_existent" does not exist in table "tags_buns" */ - public function testCounterCacheFieldException() + public function testCounterCacheFieldException(): void { $table = TableRegistry::getTableLocator()->get('Muffin/Tags.Buns', ['table' => 'tags_buns']); $table->addBehavior('Muffin/Tags.Tag', [ @@ -266,7 +266,7 @@ public function testCounterCacheFieldException() ]); } - public function testAssociationConditionsAreWorkingAsExpected() + public function testAssociationConditionsAreWorkingAsExpected(): void { $this->assertEquals(2, count($this->Table->get(1, ['contain' => ['Tags']])->tags)); } diff --git a/tests/TestCase/Model/Entity/TagAwareTraitTest.php b/tests/TestCase/Model/Entity/TagAwareTraitTest.php index a764936..76db3e3 100644 --- a/tests/TestCase/Model/Entity/TagAwareTraitTest.php +++ b/tests/TestCase/Model/Entity/TagAwareTraitTest.php @@ -14,7 +14,7 @@ class TagAwareTraitTest extends TestCase 'plugin.Muffin/Tags.Tags', ]; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -25,14 +25,14 @@ public function setUp() $this->Behavior = $table->behaviors()->Tag; } - public function tearDown() + public function tearDown(): void { parent::tearDown(); TableRegistry::getTableLocator()->clear(); unset($this->Behavior); } - public function testTag() + public function testTag(): void { $count = $this->Table->get(1)->tag_count; @@ -41,7 +41,7 @@ public function testTag() $this->assertEquals($count + 1, $this->Table->get(1)->tag_count); } - public function testUntag() + public function testUntag(): void { $entity = new TagsMuffin(['id' => 1]); $entity->untag('Color'); From 3258ee69bbaf974b788e1a9df51111a3427e18c7 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 22:06:30 -0500 Subject: [PATCH 03/26] fix: correct type-returns --- tests/Fixture/TaggedFixture.php | 2 +- tests/Fixture/TagsFixture.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Fixture/TaggedFixture.php b/tests/Fixture/TaggedFixture.php index 7744c23..1471966 100644 --- a/tests/Fixture/TaggedFixture.php +++ b/tests/Fixture/TaggedFixture.php @@ -49,7 +49,7 @@ class TaggedFixture extends TestFixture ], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { diff --git a/tests/Fixture/TagsFixture.php b/tests/Fixture/TagsFixture.php index 1e2ff32..6f43963 100644 --- a/tests/Fixture/TagsFixture.php +++ b/tests/Fixture/TagsFixture.php @@ -40,7 +40,7 @@ class TagsFixture extends TestFixture ], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { From e825e06cc85986a758c5a917f5bb6a62e8959433 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 22:15:16 -0500 Subject: [PATCH 04/26] fix: use non-deprecated methods --- tests/TestCase/Model/Behavior/TagBehaviorTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/TestCase/Model/Behavior/TagBehaviorTest.php b/tests/TestCase/Model/Behavior/TagBehaviorTest.php index 4c1e104..4bf2217 100644 --- a/tests/TestCase/Model/Behavior/TagBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/TagBehaviorTest.php @@ -252,12 +252,10 @@ public function testCounterCacheDisabled(): void $this->assertEquals($count, $result); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Field "non_existent" does not exist in table "tags_buns" - */ public function testCounterCacheFieldException(): void { + $this->expectException(\RuntimeException::class); + $this->expectedExceptionMessage('Field "non_existent" does not exist in table "tags_buns"'); $table = TableRegistry::getTableLocator()->get('Muffin/Tags.Buns', ['table' => 'tags_buns']); $table->addBehavior('Muffin/Tags.Tag', [ 'taggedCounter' => [ From 194c1368d76a0913c221399d6bf931e5e4311d3f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 22:19:00 -0500 Subject: [PATCH 05/26] fix: handle type --- src/Model/Behavior/TagBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index bd19992..2acf6f8 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -286,7 +286,7 @@ protected function _tagExists($tag) * @param string $tag Tag. * @return array The tag's ID and label. */ - protected function _normalizeTag($tag) + protected function _normalizeTag(string $tag) { $namespace = null; $label = $tag; From 9e11e04401fd666bfa8b6d314828cbe9fccbf5f8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 23:28:49 -0500 Subject: [PATCH 06/26] fix: set empty namespace correctly --- src/Model/Behavior/TagBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index 2acf6f8..2e9b031 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -288,7 +288,7 @@ protected function _tagExists($tag) */ protected function _normalizeTag(string $tag) { - $namespace = null; + $namespace = ''; $label = $tag; $separator = $this->getConfig('separator'); if (strpos($tag, $separator) !== false) { From b66f958cb7d6ca3aeb66dda0a7bddd41a6062d1e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 23:31:56 -0500 Subject: [PATCH 07/26] fix: use correct method --- tests/TestCase/Model/Behavior/TagBehaviorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Model/Behavior/TagBehaviorTest.php b/tests/TestCase/Model/Behavior/TagBehaviorTest.php index 4bf2217..03f2ee1 100644 --- a/tests/TestCase/Model/Behavior/TagBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/TagBehaviorTest.php @@ -255,7 +255,7 @@ public function testCounterCacheDisabled(): void public function testCounterCacheFieldException(): void { $this->expectException(\RuntimeException::class); - $this->expectedExceptionMessage('Field "non_existent" does not exist in table "tags_buns"'); + $this->expectExceptionMessage('Field "non_existent" does not exist in table "tags_buns"'); $table = TableRegistry::getTableLocator()->get('Muffin/Tags.Buns', ['table' => 'tags_buns']); $table->addBehavior('Muffin/Tags.Tag', [ 'taggedCounter' => [ From 2099f90b78d5c5b610cd700ce64964257e259e1d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 23:43:07 -0500 Subject: [PATCH 08/26] fix: TagAwareTraitTest --- tests/TestCase/Model/Entity/TagAwareTraitTest.php | 1 + tests/test_app/src/Application.php | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/test_app/src/Application.php diff --git a/tests/TestCase/Model/Entity/TagAwareTraitTest.php b/tests/TestCase/Model/Entity/TagAwareTraitTest.php index 76db3e3..719690a 100644 --- a/tests/TestCase/Model/Entity/TagAwareTraitTest.php +++ b/tests/TestCase/Model/Entity/TagAwareTraitTest.php @@ -5,6 +5,7 @@ use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; +use Muffin\Tags\Test\App\Model\Entity\TagsMuffin; class TagAwareTraitTest extends TestCase { diff --git a/tests/test_app/src/Application.php b/tests/test_app/src/Application.php new file mode 100644 index 0000000..c633c9b --- /dev/null +++ b/tests/test_app/src/Application.php @@ -0,0 +1,10 @@ + Date: Mon, 20 Jan 2020 23:44:19 -0500 Subject: [PATCH 09/26] fix: drop extra u --- tests/test_app/src/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_app/src/Application.php b/tests/test_app/src/Application.php index c633c9b..2a76d44 100644 --- a/tests/test_app/src/Application.php +++ b/tests/test_app/src/Application.php @@ -4,7 +4,7 @@ namespace Muffin\Tags\Test\App; use Cake\Http\BaseApplication; -u + class Application extends BaseApplication { } From 27c75bc89019cfb1aa5eafb0b7cde1595906858f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Jan 2020 23:56:15 -0500 Subject: [PATCH 10/26] chore: add missing config folder --- tests/test_app/config/bootstrap.php | 2 ++ tests/test_app/config/routes.php | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 tests/test_app/config/bootstrap.php create mode 100644 tests/test_app/config/routes.php diff --git a/tests/test_app/config/bootstrap.php b/tests/test_app/config/bootstrap.php new file mode 100644 index 0000000..c73d229 --- /dev/null +++ b/tests/test_app/config/bootstrap.php @@ -0,0 +1,2 @@ + Date: Tue, 21 Jan 2020 00:02:37 -0500 Subject: [PATCH 11/26] fix: add test app namespace to composer --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 769450d..37ad4a2 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,8 @@ }, "autoload-dev": { "psr-4": { - "Muffin\\Tags\\Test\\": "tests" + "Muffin\\Tags\\Test\\": "tests", + "Muffin\\Tags\\Test\\App\\": "tests/test_app/src" } }, "prefer-stable": true, From ef4bd3ff84fb7e59fd2603a59df5493428ec4a6a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:14:45 -0500 Subject: [PATCH 12/26] fix: correct comment --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index 80a0dfc..f17e03d 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -6,7 +6,7 @@ use Cake\Core\BasePlugin; /** - * Plugin class for tokenize + * Plugin class for tags */ class Plugin extends BasePlugin { From a18ac1ea456c6c7dca24c91de2b0d79a205cc312 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:43:31 -0500 Subject: [PATCH 13/26] chore: update docs --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a7d967..228ede3 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,16 @@ composer require muffin/tags You then need to load the plugin. You can use the shell command: -```php +``` bin/cake plugin load Muffin/Tags ``` +or by manually adding the following line to `src/Application.php`: + +```php +$this->addPlugin('Muffin/Obfuscate'); +``` + ## Usage ## Quick Start Guide From 9a1012e74b7f02d029ddc380fed783bee9bc09a4 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:35:27 +0530 Subject: [PATCH 14/26] Cleanup composer.json --- composer.json | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 37ad4a2..bd18802 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "muffin/tags", - "description": "Tags plugin for CakePHP 3.x", + "description": "Tags plugin for CakePHP", "type": "cakephp-plugin", "keywords": [ "cakephp", @@ -30,15 +30,12 @@ "source": "https://github.com/usemuffin/tags" }, "require": { - "cakephp/orm": "^4.0", - "cakephp/migrations": "^3.0" + "cakephp/orm": "^4.0" }, "require-dev": { "cakephp/cakephp": "^4.0", "cakephp/cakephp-codesniffer": "^4.0", - "phpstan/phpstan": "^0.12", - "phpunit/phpunit": "~8.5.0", - "psalm/phar": "^3.7" + "phpunit/phpunit": "~8.5.0" }, "suggest": { "muffin/slug": "For adding slugs to tags" @@ -54,9 +51,7 @@ "Muffin\\Tags\\Test\\App\\": "tests/test_app/src" } }, - "prefer-stable": true, "config": { "sort-packages": true - }, - "minimum-stability": "dev" + } } From 588a1a09ad655ac182ad4d1b80bbe7f22c08622b Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:35:49 +0530 Subject: [PATCH 15/26] Cleanup .editorconfig --- .editorconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index bd0ddd7..5b9b751 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org -root = false +root = true [*] indent_style = space @@ -12,5 +12,4 @@ insert_final_newline = true trim_trailing_whitespace = true [*.yml] -indent_style = space indent_size = 2 From eaeba25a29fbe6a345009c0da738878529f70707 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:36:26 +0530 Subject: [PATCH 16/26] Update copyright year --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 5137da5..d7be439 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 Use Muffin +Copyright (c) 2015-Present Use Muffin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 228ede3..79cb51f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ http://github.com/usemuffin/tags/issues ## License -Copyright (c) 2015, [Use Muffin] and licensed under [The MIT License][mit]. +Copyright (c) 2015-Present, [Use Muffin] and licensed under [The MIT License][mit]. [cakephp]:http://cakephp.org [composer]:http://getcomposer.org From 765fca9981ff001983fae66e85b2564a029934cb Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:38:17 +0530 Subject: [PATCH 17/26] Cleanup phpunit.xml --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ef26a93..e6a1378 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,7 +25,6 @@ ./src/ - ./src/ From 2b494aff983e4946e5e7c3959f21aa7bbb205d5d Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:38:48 +0530 Subject: [PATCH 18/26] Cleanup phpstan config --- phpstan-baseline.neon | 2 -- phpstan.neon | 5 ----- 2 files changed, 7 deletions(-) delete mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index f51e71c..0000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,2 +0,0 @@ -parameters: - ignoreErrors: [] diff --git a/phpstan.neon b/phpstan.neon index a61fda5..a03c486 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,4 @@ -includes: - - phpstan-baseline.neon - parameters: level: 6 checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false - excludes_analyse: - - */src/TestSuite/* From de7ee6be3ddc7996fd741e9a3b7fe906587a68d8 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:39:39 +0530 Subject: [PATCH 19/26] Remove scrutinizer config --- .scrutinizer.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 27146f7..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,21 +0,0 @@ -imports: - - php - -filter: - excluded_paths: - - docs/ - - tests/ -tools: - php_mess_detector: true - php_cpd: - excluded_dirs: - - docs/ - - tests/ - php_loc: - excluded_dirs: - - docs/ - - tests/ - php_pdepend: - excluded_dirs: - 1: docs/ - 2: tests/ From dc725c4738c792933eefd2bb7815fccc31d5e183 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:41:52 +0530 Subject: [PATCH 20/26] Simplify tests bootstrap file --- tests/bootstrap.php | 109 ++++++++++---------------------------------- 1 file changed, 23 insertions(+), 86 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 38252b9..dd773bd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,90 +1,27 @@ 'Muffin\Tags\Test\App', - 'encoding' => 'UTF-8', - 'fullBaseUrl' => 'http://localhost' -]); -Cake\Core\Configure::write('debug', true); - -$TMP = new \Cake\Filesystem\Folder(TMP); -$TMP->create(TMP . 'cache/models', 0777); -$TMP->create(TMP . 'cache/persistent', 0777); -$TMP->create(TMP . 'cache/views', 0777); - -$cache = [ - 'default' => [ - 'engine' => 'File' - ], - '_cake_core_' => [ - 'className' => 'File', - 'prefix' => 'muffin_tags_myapp_cake_core_', - 'path' => CACHE . 'persistent/', - 'serialize' => true, - 'duration' => '+10 seconds' - ], - '_cake_model_' => [ - 'className' => 'File', - 'prefix' => 'muffin_tags_my_app_cake_model_', - 'path' => CACHE . 'models/', - 'serialize' => 'File', - 'duration' => '+10 seconds' - ] -]; - -Cake\Cache\Cache::setConfig($cache); -Cake\Core\Configure::write('Session', [ - 'defaults' => 'php' -]); - -// Ensure default test connection is defined -if (!getenv('db_dsn')) { - putenv('db_dsn=sqlite:///:memory:'); -} - -Cake\Datasource\ConnectionManager::setConfig('test', [ - 'url' => getenv('db_dsn'), - 'timezone' => 'UTC' -]); +chdir($root); -Plugin::getCollection()->add(new \Muffin\Tags\Plugin()); +require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; From f224b5fa8e8a7adfd591d1a9268ae6494af52b2a Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:42:21 +0530 Subject: [PATCH 21/26] Remove stickler config --- .stickler.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .stickler.yml diff --git a/.stickler.yml b/.stickler.yml deleted file mode 100644 index 6ace1fe..0000000 --- a/.stickler.yml +++ /dev/null @@ -1,11 +0,0 @@ -linters: - phpcs: - standard: CakePHP - extensions: 'php,ctp' - fixer: true -files: - ignore: - - 'vendor/*' -fixers: - enable: true - workflow: commit From 61912eb7097ccec35caeacfcce033e1dd2fe5330 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:45:04 +0530 Subject: [PATCH 22/26] Cleanup travis config --- .travis.yml | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index af10731..d1a2701 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ matrix: fast_finish: true include: - - php: 7.2 + - php: 7.3 env: PHPCS=1 DEFAULT=0 - - php: 7.2 + - php: 7.3 env: STATIC_ANALYSIS=1 DEFAULT=0 before_script: @@ -37,29 +37,18 @@ before_script: - if [[ $DB = 'mysql' ]]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi - - if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^4.0; fi - - if [[ $STATIC_ANALYSIS = 1 ]]; then composer require --dev phpstan/phpstan:^0.12 psalm/phar:^3.7; fi + - if [[ $PHPCS == 1 ]]; then composer require cakephp/cakephp-codesniffer:^4.0; fi + - if [[ $STATIC_ANALYSIS == 1 ]]; then composer require --dev phpstan/phpstan:^0.12 psalm/phar:^3.8; fi script: - - | - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then - mkdir -p build/logs - vendor/bin/phpunit --coverage-clover=build/logs/clover.xml - fi + - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi + - if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - - if [[ $STATIC_ANALYSIS = 1 ]]; then vendor/bin/phpstan.phar analyse src && vendor/bin/psalm.phar --show-info=false; fi + - if [[ $STATIC_ANALYSIS == 1 ]]; then vendor/bin/phpstan.phar analyse src && vendor/bin/psalm.phar --show-info=false; fi after_success: - - | - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar - chmod +x php-coveralls.phar - ./php-coveralls.phar - fi + - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi notifications: email: false From 78293436eace4cb7fed74b9b5fd93d014a65569d Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:51:22 +0530 Subject: [PATCH 23/26] Strict types --- src/Model/Behavior/TagBehavior.php | 17 +++++++++-------- src/Model/Entity/TagAwareTrait.php | 6 +++--- src/Plugin.php | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index 2e9b031..021b35d 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -5,6 +5,7 @@ use ArrayObject; use Cake\Event\Event; +use Cake\Event\EventInterface; use Cake\ORM\Behavior; use Cake\Utility\Text; use RuntimeException; @@ -75,12 +76,12 @@ public function implementedEvents(): array /** * Before marshal callaback * - * @param \Cake\Event\Event $event The Model.beforeMarshal event. + * @param \Cake\Event\EventInterface $event The Model.beforeMarshal event. * @param \ArrayObject $data Data. * @param \ArrayObject $options Options. * @return void */ - public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) + public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) { $field = $this->getConfig('tagsAssoc.propertyName'); if (!empty($data[$field]) && (!is_array($data[$field]) || !array_key_exists('_ids', $data[$field]))) { @@ -97,7 +98,7 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti * * @return void */ - public function bindAssociations() + public function bindAssociations(): void { $config = $this->getConfig(); $tagsAlias = $config['tagsAlias']; @@ -159,7 +160,7 @@ public function bindAssociations() * @return void * @throws \RuntimeException If configured counter cache field does not exist in table. */ - public function attachCounters() + public function attachCounters(): void { $config = $this->getConfig(); $tagsAlias = $config['tagsAlias']; @@ -206,7 +207,7 @@ public function attachCounters() * @param array|string $tags List of tags as an array or a delimited string (comma by default). * @return array Normalized tags valid to be marshaled. */ - public function normalizeTags($tags) + public function normalizeTags($tags): array { if (is_string($tags)) { $tags = explode($this->getConfig('delimiter'), $tags); @@ -250,7 +251,7 @@ public function normalizeTags($tags) * @param string $tag Tag label. * @return string */ - protected function _getTagKey($tag) + protected function _getTagKey(string $tag): string { return strtolower(Text::slug($tag)); } @@ -261,7 +262,7 @@ protected function _getTagKey($tag) * @param string $tag Tag key. * @return null|int */ - protected function _tagExists($tag) + protected function _tagExists(string $tag): ?int { $tagsTable = $this->_table->{$this->getConfig('tagsAlias')}->getTarget(); $result = $tagsTable->find() @@ -286,7 +287,7 @@ protected function _tagExists($tag) * @param string $tag Tag. * @return array The tag's ID and label. */ - protected function _normalizeTag(string $tag) + protected function _normalizeTag(string $tag): array { $namespace = ''; $label = $tag; diff --git a/src/Model/Entity/TagAwareTrait.php b/src/Model/Entity/TagAwareTrait.php index 56139d9..8a104d4 100644 --- a/src/Model/Entity/TagAwareTrait.php +++ b/src/Model/Entity/TagAwareTrait.php @@ -14,7 +14,7 @@ trait TagAwareTrait * @param bool $merge Whether to merge or replace tags. Default true. * @return bool|\Cake\ORM\Entity False on failure, entity on success. */ - public function tag($tags, $merge = true) + public function tag($tags, bool $merge = true) { return $this->_updateTags($tags, $merge ? 'append' : 'replace'); } @@ -22,7 +22,7 @@ public function tag($tags, $merge = true) /** * Untag entity from given tags. * - * @param string|array $tags List of tags as an array or a delimited string (comma by default). + * @param string|array|null $tags List of tags as an array or a delimited string (comma by default). * If no value is passed all tags will be removed. * @return bool|\Cake\ORM\Entity False on failure, entity on success. */ @@ -86,7 +86,7 @@ function ($i) { * Valid values 'append', 'replace'. * @return bool|\Cake\ORM\Entity False on failure, entity on success. */ - protected function _updateTags($tags, $saveStrategy) + protected function _updateTags($tags, string $saveStrategy) { $table = TableRegistry::getTableLocator()->get($this->source()); $behavior = $table->behaviors()->Tag; diff --git a/src/Plugin.php b/src/Plugin.php index f17e03d..da71012 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -16,4 +16,25 @@ class Plugin extends BasePlugin * @var string */ protected $name = 'Tags'; + + /** + * Do bootstrapping or not + * + * @var bool + */ + protected $bootstrapEnabled = false; + + /** + * Load routes or not + * + * @var bool + */ + protected $routesEnabled = false; + + /** + * Console middleware + * + * @var bool + */ + protected $consoleEnabled = false; } From c56fc790d330ac78171272aeefac07733d75b9df Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:52:33 +0530 Subject: [PATCH 24/26] Cleanup contirbuting file --- CONTRIBUTING.md | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f198e2..f778088 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ Tags loves to welcome your contributions. There are several ways to help out: * Create a ticket in GitHub, if you have found a bug * Write testcases for open bug tickets * Write patches for open bug/feature tickets, preferably with testcases included -* Contribute to the [documentation](https://github.com/UseMuffin/Tags/tree/gh-pages) +* Contribute to the documentation/readme There are a few guidelines that we need contributors to follow so that we have a chance of keeping on top of things. @@ -59,21 +59,6 @@ Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) repository to setup the CakePHP standard. The README contains installation info for the sniff and phpcs. -## Documentation - -You can build the documentation using Docker via the following commands: - - # go to the docs dir - cd docs - - # build the docs - docker build . - - # make the html - docker run -it --rm -v $(pwd)/docs:/data UseMuffin/Tags make html - - # open the generated html docs in docs/_build/html - # Additional Resources * [CakePHP coding standards](https://book.cakephp.org/4/en/contributing/cakephp-coding-conventions.html) From de01930a3311037c1343e983f27b2f1221194fc6 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:56:25 +0530 Subject: [PATCH 25/26] Fix CS error --- src/Model/Behavior/TagBehavior.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Model/Behavior/TagBehavior.php b/src/Model/Behavior/TagBehavior.php index 021b35d..6987da1 100644 --- a/src/Model/Behavior/TagBehavior.php +++ b/src/Model/Behavior/TagBehavior.php @@ -4,7 +4,6 @@ namespace Muffin\Tags\Model\Behavior; use ArrayObject; -use Cake\Event\Event; use Cake\Event\EventInterface; use Cake\ORM\Behavior; use Cake\Utility\Text; From c99db379be944eba7dffb41583235e6d18790785 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 Jan 2020 18:58:24 +0530 Subject: [PATCH 26/26] Add missing dependency --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bd18802..33ed284 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "source": "https://github.com/usemuffin/tags" }, "require": { - "cakephp/orm": "^4.0" + "cakephp/orm": "^4.0", + "cakephp/utility": "^4.0" }, "require-dev": { "cakephp/cakephp": "^4.0",