From 7920b08e32900384216fd6b22f2ef9025cc1421c Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 11 Apr 2018 20:05:11 -0600 Subject: [PATCH] PHPCS first pass --- composer.json | 4 +- phpcs.xml.dist | 27 ++++++++++++ src/Entity/AuditEntity.php | 1 - src/Entity/Revision.php | 1 - src/Entity/RevisionEntity.php | 1 - src/Entity/RevisionType.php | 1 - src/Entity/TargetEntity.php | 1 - src/Fixture/RevisionTypeFixture.php | 4 +- src/Loader/EntityAutoloader.php | 16 +++---- src/Loader/JoinEntityAutoloader.php | 16 +++---- src/Mapping/Driver/EntityDriver.php | 10 ++--- test/TestConfig.php | 20 ++++----- test/ZFTest/Module.php | 28 ++++++------ test/ZFTest/config/module.config.php | 60 ++++++++++++------------- test/audit_epoch.sql | 4 +- test/autoload/tests.global.php | 65 ++++++++++++++-------------- 16 files changed, 139 insertions(+), 120 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/composer.json b/composer.json index 40e999e..b168e92 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ "php": ">=7.1", "zendframework/zend-servicemanager": "^3.3", "zendframework/zend-authentication": "^2.5.3", - "zendframework/zend-code": "3.2.0", "doctrine/doctrine-orm-module": "^1.1.5 || ^2.1", "api-skeletons/zf-doctrine-data-fixture": "^5.0.7", "api-skeletons/zf-doctrine-repository": "^1.0" }, "require-dev": { - "squizlabs/php_codesniffer": "^2", + "zendframework/zend-code": "3.2.0", + "api-skeletons/coding-standard": "^1.0", "phpunit/phpunit": "^4.0" }, "autoload": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..330895a --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,27 @@ + + + v1.0 Coding Standard for API Skeletons + src + test + Bootstrap.php + */data/* + + + + + + + + + + + + + + + + + + + + diff --git a/src/Entity/AuditEntity.php b/src/Entity/AuditEntity.php index 5b1ef00..34a0855 100644 --- a/src/Entity/AuditEntity.php +++ b/src/Entity/AuditEntity.php @@ -110,4 +110,3 @@ public function getTargetEntity() return $this->targetEntity; } } - diff --git a/src/Entity/Revision.php b/src/Entity/Revision.php index 9180d5d..f192f1f 100644 --- a/src/Entity/Revision.php +++ b/src/Entity/Revision.php @@ -243,4 +243,3 @@ public function getRevisionEntity() return $this->revisionEntity; } } - diff --git a/src/Entity/RevisionEntity.php b/src/Entity/RevisionEntity.php index 0146fab..a28a31d 100644 --- a/src/Entity/RevisionEntity.php +++ b/src/Entity/RevisionEntity.php @@ -116,4 +116,3 @@ public function getRevisionType() return $this->revisionType; } } - diff --git a/src/Entity/RevisionType.php b/src/Entity/RevisionType.php index 6fb1044..86b87f1 100644 --- a/src/Entity/RevisionType.php +++ b/src/Entity/RevisionType.php @@ -98,4 +98,3 @@ public function getRevisionEntity() return $this->revisionEntity; } } - diff --git a/src/Entity/TargetEntity.php b/src/Entity/TargetEntity.php index f3b00e3..316ebae 100644 --- a/src/Entity/TargetEntity.php +++ b/src/Entity/TargetEntity.php @@ -254,4 +254,3 @@ public function getParent() return $this->parent; } } - diff --git a/src/Fixture/RevisionTypeFixture.php b/src/Fixture/RevisionTypeFixture.php index 2e58527..f83f80a 100644 --- a/src/Fixture/RevisionTypeFixture.php +++ b/src/Fixture/RevisionTypeFixture.php @@ -12,12 +12,12 @@ class RevisionTypeFixture implements public function load(ObjectManager $auditObjectManager) { // Add RevisionType - foreach (array('insert', 'update', 'delete', 'epoch') as $name) { + foreach (['insert', 'update', 'delete', 'epoch'] as $name) { $revisionType = $auditObjectManager ->getRepository('ZF\Doctrine\Audit\Entity\RevisionType') ->findOneBy( [ - 'name' => $name, + 'name' => $name, ] ); diff --git a/src/Loader/EntityAutoloader.php b/src/Loader/EntityAutoloader.php index 701d295..93be48c 100644 --- a/src/Loader/EntityAutoloader.php +++ b/src/Loader/EntityAutoloader.php @@ -55,14 +55,14 @@ public function loadClass($auditClassName, $type) $auditClass->addProperty('revisionEntity', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addMethod( 'getRevisionEntity', - array(), + [], MethodGenerator::FLAG_PUBLIC, " return \$this->revisionEntity;" ); $auditClass->addMethod( 'setRevisionEntity', - array('value'), + ['value'], MethodGenerator::FLAG_PUBLIC, " \$this->revisionEntity = \$value;\n\nreturn \$this; " @@ -80,13 +80,13 @@ public function loadClass($auditClassName, $type) $auditClass->addMethod( 'getAssociationMappings', - array(), + [], MethodGenerator::FLAG_PUBLIC, "return unserialize('" . serialize($auditedClassMetadata->getAssociationMappings()) . "');" ); // Add exchange array method - $setters = array(); + $setters = []; foreach ($fields as $fieldName) { $setters[] = '$this->' . $fieldName . ' = (isset($data["' . $fieldName . '"])) ? $data["' . $fieldName . '"]: null;'; @@ -95,14 +95,14 @@ public function loadClass($auditClassName, $type) $auditClass->addMethod( 'getArrayCopy', - array(), + [], MethodGenerator::FLAG_PUBLIC, "return array(\n" . implode(",\n", $arrayCopy) . "\n);" ); $auditClass->addMethod( 'exchangeArray', - array('data'), + ['data'], MethodGenerator::FLAG_PUBLIC, implode("\n", $setters) ); @@ -110,9 +110,9 @@ public function loadClass($auditClassName, $type) // Add function to return the entity class this entity audits $auditClass->addMethod( 'getAuditedEntityClass', - array(), + [], MethodGenerator::FLAG_PUBLIC, - " return '" . addslashes($className) . "';" + " return '" . addslashes($className) . "';" ); eval($auditClass->generate()); diff --git a/src/Loader/JoinEntityAutoloader.php b/src/Loader/JoinEntityAutoloader.php index 55849e1..266e6fe 100644 --- a/src/Loader/JoinEntityAutoloader.php +++ b/src/Loader/JoinEntityAutoloader.php @@ -64,14 +64,14 @@ public function loadClass($auditClassName, $type) $auditClass->addProperty('revisionEntity', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addMethod( 'getRevisionEntity', - array(), + [], MethodGenerator::FLAG_PUBLIC, " return \$this->revisionEntity;" ); $auditClass->addMethod( 'setRevisionEntity', - array('value'), + ['value'], MethodGenerator::FLAG_PUBLIC, " \$this->revisionEntity = \$value;\n\nreturn \$this; " @@ -98,13 +98,13 @@ public function loadClass($auditClassName, $type) $auditClass->addMethod( 'getAssociationMappings', - array(), + [], MethodGenerator::FLAG_PUBLIC, "return unserialize('" . serialize($mapping) . "');" ); // Add exchange array method - $setters = array(); + $setters = []; foreach ($fields as $field) { $setters[] = '$this->' . $field['name'] . ' = (isset($data["' . $field['name'] . '"])) ? $data["' . $field['name'] . '"]: null;'; @@ -113,14 +113,14 @@ public function loadClass($auditClassName, $type) $auditClass->addMethod( 'getArrayCopy', - array(), + [], MethodGenerator::FLAG_PUBLIC, "return array(\n" . implode(",\n", $arrayCopy) . "\n);" ); $auditClass->addMethod( 'exchangeArray', - array('data'), + ['data'], MethodGenerator::FLAG_PUBLIC, implode("\n", $setters) ); @@ -128,9 +128,9 @@ public function loadClass($auditClassName, $type) // Add function to return the entity class this entity audits $auditClass->addMethod( 'getAuditedEntityClass', - array(), + [], MethodGenerator::FLAG_PUBLIC, - " return '" . addslashes($auditClassName) . "';" + " return '" . addslashes($auditClassName) . "';" ); // echo "Created " . $auditClass->getName() . "\n" . $auditClass->getNamespaceName() . "\n"; diff --git a/src/Mapping/Driver/EntityDriver.php b/src/Mapping/Driver/EntityDriver.php index ea16a8f..aee21b9 100644 --- a/src/Mapping/Driver/EntityDriver.php +++ b/src/Mapping/Driver/EntityDriver.php @@ -32,7 +32,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $metadataFactory = $this->getObjectManager()->getMetadataFactory(); $builder = new ClassMetadataBuilder($metadata); - $identifiers = array(); + $identifiers = []; // Get the entity this entity audits $metadataClassName = $metadata->getName(); @@ -57,11 +57,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $builder->addField( $fieldName, $auditedClassMetadata->getTypeOfField($fieldName), - array( + [ 'columnName' => $auditedClassMetadata->getColumnName($fieldName), 'nullable' => true, 'quoted' => true - ) + ] ); if ($auditedClassMetadata->isIdentifier($fieldName)) { @@ -80,7 +80,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $builder->addField( $mapping['fieldName'], 'bigint', - array('nullable' => true, 'columnName' => $field) + ['nullable' => true, 'columnName' => $field] ); } } elseif (isset($mapping['joinColumnFieldNames'])) { @@ -89,7 +89,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $builder->addField( $mapping['fieldName'], 'bigint', - array('nullable' => true, 'columnName' => $field) + ['nullable' => true, 'columnName' => $field] ); } } else { diff --git a/test/TestConfig.php b/test/TestConfig.php index 57f6c23..36a4122 100644 --- a/test/TestConfig.php +++ b/test/TestConfig.php @@ -1,6 +1,6 @@ array( +return [ + 'modules' => [ 'Zend\Router', 'ZF\Doctrine\Audit', 'ZFTest\Doctrine\Audit', @@ -8,15 +8,15 @@ 'DoctrineORMModule', 'ZF\Doctrine\DataFixture', 'ZF\Doctrine\Repository', - ), - 'module_listener_options' => array( - 'config_glob_paths' => array( + ], + 'module_listener_options' => [ + 'config_glob_paths' => [ '../../../config/autoload/{,*.}{global,local}.php', 'autoload/{,*.}{global,local}.php', - ), - 'module_paths' => array( + ], + 'module_paths' => [ 'module', 'vendor', - ), - ), -); + ], + ], +]; diff --git a/test/ZFTest/Module.php b/test/ZFTest/Module.php index bd76c4d..e49b2ed 100644 --- a/test/ZFTest/Module.php +++ b/test/ZFTest/Module.php @@ -15,13 +15,13 @@ class Module implements { public function getAutoloaderConfig() { - return array( - 'Zend\Loader\StandardAutoloader' => array( - 'namespaces' => array( + return [ + 'Zend\Loader\StandardAutoloader' => [ + 'namespaces' => [ __NAMESPACE__ => __DIR__, - ), - ), - ); + ], + ], + ]; } public function getConfig() @@ -31,17 +31,17 @@ public function getConfig() public function getServiceConfig() { - return array( - 'factories' => array( - 'doctrine.entitymanager.orm_zf_doctrine_audit' + return [ + 'factories' => [ + 'doctrine.entitymanager.orm_zf_doctrine_audit' => new EntityManagerFactory('orm_zf_doctrine_audit'), - 'doctrine.connection.orm_zf_doctrine_audit' + 'doctrine.connection.orm_zf_doctrine_audit' => new DBALConnectionFactory('orm_zf_doctrine_audit'), - 'doctrine.configuration.orm_zf_doctrine_audit' + 'doctrine.configuration.orm_zf_doctrine_audit' => new ConfigurationFactory('orm_zf_doctrine_audit'), - 'doctrine.eventmanager.orm_zf_doctrine_audit' + 'doctrine.eventmanager.orm_zf_doctrine_audit' => new EventManagerFactory('orm_zf_doctrine_audit'), - ), - ); + ], + ]; } } diff --git a/test/ZFTest/config/module.config.php b/test/ZFTest/config/module.config.php index 2931143..e1c9ba2 100644 --- a/test/ZFTest/config/module.config.php +++ b/test/ZFTest/config/module.config.php @@ -1,23 +1,23 @@ array( - 'connection' => array( - 'orm_default' => array( - 'params' => array( +return [ + 'doctrine' => [ + 'connection' => [ + 'orm_default' => [ + 'params' => [ 'charset' => 'utf8', - ), - ), - 'orm_zf_doctrine_audit' => array( + ], + ], + 'orm_zf_doctrine_audit' => [ 'eventmanager' => 'orm_zf_doctrine_audit', - 'params' => array( + 'params' => [ 'charset' => 'utf8', - ), - ), - ), + ], + ], + ], - 'configuration' => array( - 'orm_zf_doctrine_audit' => array( + 'configuration' => [ + 'orm_zf_doctrine_audit' => [ 'metadata_cache' => 'array', 'query_cache' => 'array', 'result_cache' => 'array', @@ -25,25 +25,25 @@ 'generate_proxies' => true, 'proxy_dir' => 'data/DoctrineORMModule/Proxy', 'proxy_namespace' => 'DoctrineORMModule\Proxy', - 'filters' => array() - ), - ), + 'filters' => [] + ], + ], - 'driver' => array( - 'orm_zf_doctrine_audit' => array( + 'driver' => [ + 'orm_zf_doctrine_audit' => [ 'class' => 'Doctrine\\ORM\\Mapping\\Driver\\DriverChain', - ), - ), + ], + ], - 'entitymanager' => array( - 'orm_zf_doctrine_audit' => array( + 'entitymanager' => [ + 'orm_zf_doctrine_audit' => [ 'connection' => 'orm_zf_doctrine_audit', 'configuration' => 'orm_zf_doctrine_audit', - ), - ), + ], + ], - 'eventmanager' => array( - 'orm_zf_doctrine_audit' => array(), - ), - ), -); + 'eventmanager' => [ + 'orm_zf_doctrine_audit' => [], + ], + ], +]; diff --git a/test/audit_epoch.sql b/test/audit_epoch.sql index b1257c0..c24d4b8 100644 --- a/test/audit_epoch.sql +++ b/test/audit_epoch.sql @@ -1,5 +1,3 @@ - - SELECT 'Begin Artist offset 0 rows 200' as '', now() as ''; DROP PROCEDURE IF EXISTS zf_doctrine_audit_epoch_Artist; @@ -40,7 +38,7 @@ BEGIN `revisionEntity_id` ) SELECT var_id, - var_name, +convert(var_name using utf8), var_revision_entity_id; END LOOP read_loop; diff --git a/test/autoload/tests.global.php b/test/autoload/tests.global.php index f7e34b7..6e86f8b 100644 --- a/test/autoload/tests.global.php +++ b/test/autoload/tests.global.php @@ -9,15 +9,15 @@ $host = 'mysql'; } -return array( - 'service_manager' => array( - 'invokables' => array( +return [ + 'service_manager' => [ + 'invokables' => [ 'Zend\Authentication\AuthenticationService' => 'Zend\Authentication\AuthenticationService', - ), - ), + ], + ], - 'zf-doctrine-audit' => array( + 'zf-doctrine-audit' => [ 'target_object_manager' => 'doctrine.entitymanager.orm_default', 'audit_object_manager' => 'doctrine.entitymanager.orm_zf_doctrine_audit', @@ -28,58 +28,57 @@ 'table_name_prefix' => '', 'table_name_suffix' => '_audit', - 'entities' => array( + 'entities' => [ 'ZFTest\Doctrine\Audit\Entity\Artist' => [], 'ZFTest\Doctrine\Audit\Entity\Album' => [], - ), + ], 'joinEntities' => [ 'ZFTest\Doctrine\Audit\Entity\UserToAlbum' => [ 'ownerEntity' => 'ZFTest\Doctrine\Audit\Entity\Album', 'tableName' => 'UserToAlbum', ], ], - ), + ], - 'doctrine' => array( - 'connection' => array( - 'orm_default' => array( + 'doctrine' => [ + 'connection' => [ + 'orm_default' => [ 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', - 'params' => array( + 'params' => [ 'user' => 'root', 'password' => '', 'host' => $host, 'dbname' => 'test', 'charset' => 'utf8', 'collate' => "utf8_unicode_ci", - ), - ), - 'orm_zf_doctrine_audit' => array( + ], + ], + 'orm_zf_doctrine_audit' => [ 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', - 'params' => array( + 'params' => [ 'user' => 'root', 'password' => '', 'host' => $host, 'dbname' => 'audit', 'charset' => 'utf8', 'collate' => "utf8_unicode_ci", - ), - ), - ), + ], + ], + ], - 'driver' => array( - 'zftest_driver' => array( + 'driver' => [ + 'zftest_driver' => [ 'class' => 'Doctrine\\ORM\\Mapping\\Driver\\XmlDriver', - 'paths' => array( + 'paths' => [ 0 => __DIR__ . '/../ZFTest/config/orm', - ), - ), - 'orm_default' => array( + ], + ], + 'orm_default' => [ 'class' => 'Doctrine\\ORM\\Mapping\\Driver\\DriverChain', - 'drivers' => array( + 'drivers' => [ 'ZFTest\\Doctrine\\Audit\\Entity' => 'zftest_driver', - ), - ), - ), - ), -); - + ], + ], + ], + ], +];