diff --git a/composer.json b/composer.json index 2ed69a9..f9a6b2e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "cakephp/plugin-installer": "*", "holt59/cakephp3-bootstrap-helpers": "dev-master", "fzaninotto/Faker": "^1.6", - "cakephp/localized": "dev-master" + "cakephp/localized": "dev-master", + "cakephp/cakephp-codesniffer": "dev-master" }, "require-dev": { "psy/psysh": "@stable", diff --git a/composer.lock b/composer.lock index b55af69..7b4e337 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": "f432e1c193e1338ed7849ad99e818d37", - "content-hash": "fcd75d5f454dcb2c710ea90ed7f7190f", + "hash": "bb63c2f79a4efd2cb80b208a89b6947e", + "content-hash": "f2392a9affbf0362ff72f281deda92b5", "packages": [ { "name": "aura/installer-default", @@ -198,6 +198,45 @@ ], "time": "2016-07-09 02:08:27" }, + { + "name": "cakephp/cakephp-codesniffer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/cakephp/cakephp-codesniffer.git", + "reference": "66e61e3b7148abe0b412f7a4537fd04c9d2d0265" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/66e61e3b7148abe0b412f7a4537fd04c9d2d0265", + "reference": "66e61e3b7148abe0b412f7a4537fd04c9d2d0265", + "shasum": "" + }, + "require": { + "squizlabs/php_codesniffer": "~2.4" + }, + "require-dev": { + "phpunit/phpunit": "4.1.*" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/cakephp-codesniffer/graphs/contributors" + } + ], + "description": "CakePHP CodeSniffer Standards", + "homepage": "http://cakephp.org", + "keywords": [ + "codesniffer", + "framework" + ], + "time": "2016-07-19 13:24:35" + }, { "name": "cakephp/chronos", "version": "0.4.11", @@ -644,6 +683,84 @@ ], "time": "2016-03-07 14:09:22" }, + { + "name": "squizlabs/php_codesniffer", + "version": "2.6.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "4edb770cb853def6e60c93abb088ad5ac2010c83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4edb770cb853def6e60c93abb088ad5ac2010c83", + "reference": "4edb770cb853def6e60c93abb088ad5ac2010c83", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2016-07-13 23:29:13" + }, { "name": "symfony/config", "version": "v3.1.2", @@ -1381,6 +1498,7 @@ "cakephp/migrations": 0, "holt59/cakephp3-bootstrap-helpers": 20, "cakephp/localized": 20, + "cakephp/cakephp-codesniffer": 20, "psy/psysh": 0 }, "prefer-stable": true, diff --git a/config/Migrations/20160707205730_AlterAddUnqueAttributeForLoginEmail.php b/config/Migrations/20160707205730_AlterAddUnqueAttributeForLoginEmail.php index 848d7ea..9374623 100644 --- a/config/Migrations/20160707205730_AlterAddUnqueAttributeForLoginEmail.php +++ b/config/Migrations/20160707205730_AlterAddUnqueAttributeForLoginEmail.php @@ -12,4 +12,3 @@ public function down() { } } - diff --git a/config/Migrations/20160709184233_AddUserIdToPosts.php b/config/Migrations/20160709184233_AddUserIdToPosts.php index 9e06e0a..e9bc4b2 100644 --- a/config/Migrations/20160709184233_AddUserIdToPosts.php +++ b/config/Migrations/20160709184233_AddUserIdToPosts.php @@ -19,7 +19,7 @@ public function change() 'null' => true ]) ->addIndex(['user_id'], ['name' => 'fk_posts_users_idx']) - ->addForeignKey('user_id', 'users', 'id', ['delete'=> 'SET_NULL', 'update'=> 'NO_ACTION']) + ->addForeignKey('user_id', 'users', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION']) ->save(); } } diff --git a/config/Migrations/20160709210604_AddDisplayNameColumn.php b/config/Migrations/20160709210604_AddDisplayNameColumn.php index 5e0d75d..52db79d 100644 --- a/config/Migrations/20160709210604_AddDisplayNameColumn.php +++ b/config/Migrations/20160709210604_AddDisplayNameColumn.php @@ -24,4 +24,3 @@ public function down() ->update(); } } - diff --git a/config/Migrations/20160709213450_ChangePasswordLength.php b/config/Migrations/20160709213450_ChangePasswordLength.php index da9e8ef..63d5a5d 100644 --- a/config/Migrations/20160709213450_ChangePasswordLength.php +++ b/config/Migrations/20160709213450_ChangePasswordLength.php @@ -26,4 +26,3 @@ public function down() ->update(); } } - diff --git a/config/Migrations/20160710160333_AlterContentToText.php b/config/Migrations/20160710160333_AlterContentToText.php index 75c966a..3498f7e 100644 --- a/config/Migrations/20160710160333_AlterContentToText.php +++ b/config/Migrations/20160710160333_AlterContentToText.php @@ -7,7 +7,7 @@ class AlterContentToText extends AbstractMigration public function change() { $this->table('posts') - ->changeColumn('content', 'text',[ + ->changeColumn('content', 'text', [ 'default' => null, 'limit' => 4294967295, 'null' => false diff --git a/config/Migrations/20160714150701_AddStatusColumnInPosts.php b/config/Migrations/20160714150701_AddStatusColumnInPosts.php index b4e8265..fa86c00 100644 --- a/config/Migrations/20160714150701_AddStatusColumnInPosts.php +++ b/config/Migrations/20160714150701_AddStatusColumnInPosts.php @@ -25,13 +25,13 @@ class AddStatusColumnInPosts extends AbstractMigration * Remember to call "create()" or "update()" and NOT "save()" when working * with the Table class. */ - public function change() - { - $this->table('posts') - ->addColumn('state', 'enum', [ - 'default' => null, - 'values' => ['published', 'pinned', 'draft'], - 'null' => false, - ])->update(); - } + public function change() + { + $this->table('posts') + ->addColumn('state', 'enum', [ + 'default' => null, + 'values' => ['published', 'pinned', 'draft'], + 'null' => false, + ])->update(); + } } diff --git a/config/Migrations/20160718160356_AddPostType.php b/config/Migrations/20160718160356_AddPostType.php index 4711f16..1155f03 100644 --- a/config/Migrations/20160718160356_AddPostType.php +++ b/config/Migrations/20160718160356_AddPostType.php @@ -30,4 +30,3 @@ public function down() ->update(); } } - diff --git a/config/Migrations/20160719203719_AlterAllowCommentToBeEmpty.php b/config/Migrations/20160719203719_AlterAllowCommentToBeEmpty.php index b4d94bb..9cbe154 100644 --- a/config/Migrations/20160719203719_AlterAllowCommentToBeEmpty.php +++ b/config/Migrations/20160719203719_AlterAllowCommentToBeEmpty.php @@ -26,4 +26,3 @@ public function down() ->update(); } } - diff --git a/config/Seeds/PostsSeed.php b/config/Seeds/PostsSeed.php index 6d567f9..59dd9d2 100644 --- a/config/Seeds/PostsSeed.php +++ b/config/Seeds/PostsSeed.php @@ -23,7 +23,7 @@ public function run() $faker = Faker\Factory::create(); $data = []; - for ($i=0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $data[] = [ 'title' => $faker->sentence(5, true), 'content' => '

' . implode('

', $faker->paragraphs(rand(3, 20), false)) . '

', diff --git a/config/Seeds/SignaturesSeed.php b/config/Seeds/SignaturesSeed.php index d24eb66..ae02225 100644 --- a/config/Seeds/SignaturesSeed.php +++ b/config/Seeds/SignaturesSeed.php @@ -22,7 +22,7 @@ public function run() $data = []; - for ($i=0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $data[] = [ 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, diff --git a/config/Seeds/UsersSeed.php b/config/Seeds/UsersSeed.php index af7ef84..9a889b9 100644 --- a/config/Seeds/UsersSeed.php +++ b/config/Seeds/UsersSeed.php @@ -1,6 +1,7 @@ 'user1', @@ -41,7 +43,7 @@ public function run() ] ]; - for ($i=0; $i < 20; $i++) { + for ($i = 0; $i < 20; $i++) { $data[] = [ 'login' => $faker->lastName . $faker->numberBetween(1, 5555), 'email' => $faker->safeEmail, diff --git a/config/bootstrap.php b/config/bootstrap.php index 705e667..3eaa663 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -162,10 +162,14 @@ */ Request::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); + + return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect(); + + return $detector->isTablet(); }); diff --git a/config/routes.php b/config/routes.php index aa3cb3a..0b4672a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -45,17 +45,17 @@ Router::scope('/auth', function (RouteBuilder $routes) { $routes->connect('/', ['controller' => 'Auth', 'action' => 'login'], ['_name' => 'auth.login']); - $routes->connect('/logout', ['controller' => 'Auth', 'action' => 'logout',], [ '_name' => 'auth.logout']); + $routes->connect('/logout', ['controller' => 'Auth', 'action' => 'logout', ], [ '_name' => 'auth.logout']); }); Router::scope('/petition', function (RouteBuilder $routes) { $routes->connect('/', ['controller' => 'Petition', 'action' => 'index'], ['_name' => 'petition.index']); - $routes->connect('/form', ['controller' => 'Petition', 'action' => 'add',], [ '_name' => 'petition.add']); - $routes->connect('/thank-you', ['controller' => 'Petition', 'action' => 'thank',], [ '_name' => 'petition.thank']); + $routes->connect('/form', ['controller' => 'Petition', 'action' => 'add', ], [ '_name' => 'petition.add']); + $routes->connect('/thank-you', ['controller' => 'Petition', 'action' => 'thank', ], [ '_name' => 'petition.thank']); }); -Router::scope('/', function (RouteBuilder $routes){ +Router::scope('/', function (RouteBuilder $routes) { $routes->connect('/', ['controller' => 'Blog', 'action' => 'index']); $routes->connect('/:id/*', ['controller' => 'Blog', 'action' => 'view'], ['pass' => ['id'], 'id' => '\d+']); diff --git a/src/Console/Installer.php b/src/Console/Installer.php index 9a09e9f..7b61441 100644 --- a/src/Console/Installer.php +++ b/src/Console/Installer.php @@ -179,12 +179,16 @@ public static function setSecuritySalt($dir, $io) if ($count == 0) { $io->write('No Security.salt placeholder to replace.'); + + return; } $result = file_put_contents($config, $content); if ($result) { $io->write('Updated Security.salt value in config/app.php'); + + return; } $io->write('Unable to update Security.salt value.'); diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 0da9f7c..685841c 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -77,7 +77,7 @@ public function initialize() 'controller' => 'Auth', 'action' => 'login' ], - 'unauthorizedRedirect'=>$this->referer() + 'unauthorizedRedirect' => $this->referer() ]); } diff --git a/src/Controller/AuthController.php b/src/Controller/AuthController.php index 18c47b5..39a5868 100644 --- a/src/Controller/AuthController.php +++ b/src/Controller/AuthController.php @@ -28,6 +28,8 @@ public function login() $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); + + return $this->redirect($this->Auth->redirectUrl()); } $this->Flash->error(__('Invalid username or password, try again')); @@ -43,5 +45,4 @@ public function logout() { return $this->redirect($this->Auth->logout()); } - } diff --git a/src/Controller/PetitionController.php b/src/Controller/PetitionController.php index 11e9053..b924b76 100644 --- a/src/Controller/PetitionController.php +++ b/src/Controller/PetitionController.php @@ -36,7 +36,8 @@ public function index() $this->add(); } - public function listSignature(){ + public function listSignature() + { $signatures = $this->paginate($this->Signatures); $this->set(compact('signatures')); @@ -50,6 +51,8 @@ public function add() $petition = $this->Signatures->patchEntity($signature, $this->request->data); if ($this->Signatures->save($signature)) { $this->Flash->success(__('The signature has been saved.')); + + return $this->redirect(['action' => 'thank']); } else { $this->Flash->error(__('The signature could not be saved. Please, try again.')); @@ -66,8 +69,5 @@ public function add() */ public function thank() { - } - - } diff --git a/src/Controller/PostsController.php b/src/Controller/PostsController.php index 4ed2b59..e1b61d7 100644 --- a/src/Controller/PostsController.php +++ b/src/Controller/PostsController.php @@ -61,6 +61,8 @@ public function add() $post->user_id = $this->Auth->user('id'); if ($this->Posts->save($post)) { $this->Flash->success(__('The post has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The post could not be saved. Please, try again.')); @@ -88,6 +90,8 @@ public function edit($id = null) $post = $this->Posts->patchEntity($post, $this->request->data); if ($this->Posts->save($post)) { $this->Flash->success(__('The post has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The post could not be saved. Please, try again.')); @@ -114,7 +118,8 @@ public function delete($id = null) } else { $this->Flash->error(__('The post could not be deleted. Please, try again.')); } + + return $this->redirect(['action' => 'index']); } - } diff --git a/src/Controller/SignaturesController.php b/src/Controller/SignaturesController.php index 0d38ce2..2004ae9 100644 --- a/src/Controller/SignaturesController.php +++ b/src/Controller/SignaturesController.php @@ -53,6 +53,8 @@ public function add() $signature = $this->Signatures->patchEntity($signature, $this->request->data); if ($this->Signatures->save($signature)) { $this->Flash->success(__('The signature has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The signature could not be saved. Please, try again.')); @@ -78,6 +80,8 @@ public function edit($id = null) $signature = $this->Signatures->patchEntity($signature, $this->request->data); if ($this->Signatures->save($signature)) { $this->Flash->success(__('The signature has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The signature could not be saved. Please, try again.')); @@ -103,6 +107,8 @@ public function delete($id = null) } else { $this->Flash->error(__('The signature could not be deleted. Please, try again.')); } + + return $this->redirect(['action' => 'index']); } } diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index a94895f..8457ac0 100644 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -53,6 +53,8 @@ public function add() $user = $this->Users->patchEntity($user, $this->request->data); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The user could not be saved. Please, try again.')); @@ -78,6 +80,8 @@ public function edit($id = null) $user = $this->Users->patchEntity($user, $this->request->data); if ($this->Users->save($user)) { $this->Flash->success(__('The user has been saved.')); + + return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The user could not be saved. Please, try again.')); @@ -103,6 +107,8 @@ public function delete($id = null) } else { $this->Flash->error(__('The user could not be deleted. Please, try again.')); } + + return $this->redirect(['action' => 'index']); } } diff --git a/src/Model/Entity/Post.php b/src/Model/Entity/Post.php index 6780fa5..a24bcf5 100644 --- a/src/Model/Entity/Post.php +++ b/src/Model/Entity/Post.php @@ -35,7 +35,8 @@ class Post extends Entity 'id' => false ]; - public function isHasBennModifited(){ + public function isHasBennModifited() + { // Lte = Less or equal return $this->created->modify('+15 minutes')->lte($this->modified); } diff --git a/src/Model/Entity/User.php b/src/Model/Entity/User.php index 1006f30..2977420 100644 --- a/src/Model/Entity/User.php +++ b/src/Model/Entity/User.php @@ -44,7 +44,7 @@ class User extends Entity protected function _setPassword($password) { - if(strlen($password) > 0){ + if (strlen($password) > 0) { return (new DefaultPasswordHasher)->hash($password); } } diff --git a/src/Model/Table/PostsTable.php b/src/Model/Table/PostsTable.php index 5207b60..91920ac 100644 --- a/src/Model/Table/PostsTable.php +++ b/src/Model/Table/PostsTable.php @@ -76,7 +76,7 @@ public function validationDefault(Validator $validator) $validator ->requirePresence('link_target', 'create') - ->allowEmpty('link_target', function($context) { + ->allowEmpty('link_target', function ($context) { return $context && $context['data'] && $context['data']['type'] != 'link'; }); @@ -93,6 +93,8 @@ public function validationDefault(Validator $validator) public function buildRules(RulesChecker $rules) { $rules->add($rules->existsIn(['user_id'], 'Users')); + + return $rules; } diff --git a/src/Model/Table/SignaturesTable.php b/src/Model/Table/SignaturesTable.php index 3e79287..6f1394a 100644 --- a/src/Model/Table/SignaturesTable.php +++ b/src/Model/Table/SignaturesTable.php @@ -86,6 +86,8 @@ public function validationDefault(Validator $validator) public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['email'])); + + return $rules; } } diff --git a/src/Model/Table/UsersTable.php b/src/Model/Table/UsersTable.php index b8bff7b..3eac473 100644 --- a/src/Model/Table/UsersTable.php +++ b/src/Model/Table/UsersTable.php @@ -90,6 +90,8 @@ public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['login'])); $rules->add($rules->isUnique(['email'])); + + return $rules; } } diff --git a/src/Shell/ConsoleShell.php b/src/Shell/ConsoleShell.php index 2b38906..8d04572 100644 --- a/src/Shell/ConsoleShell.php +++ b/src/Shell/ConsoleShell.php @@ -42,6 +42,8 @@ public function main() $this->err(''); $this->err('$ php composer.phar require --dev psy/psysh'); $this->err(''); + + return self::CODE_ERROR; } @@ -74,6 +76,8 @@ public function getOptionParser() "\n\n" . 'You will need to have psysh installed for this Shell to work.' ); + + return $parser; } }