From 2071f9dee3f72c8789f4c9752b5a2747f83e6dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sun, 17 Mar 2019 18:25:32 +0100 Subject: [PATCH] Fix CS --- .php_cs | 1 + src/Cli/Command/AbstractCommand.php | 4 +- .../Command/Helper/KeyOptionCommandTrait.php | 4 +- src/Cli/Configuration/AcmeConfiguration.php | 4 +- src/Cli/Configuration/DomainConfiguration.php | 12 +++--- src/Core/Challenge/Dns/LibDnsResolver.php | 4 +- src/Core/Challenge/Dns/Route53Solver.php | 4 +- src/Core/Http/SecureHttpClient.php | 2 +- src/Core/Util/JsonDecoder.php | 2 +- src/Ssl/Signer/DataSigner.php | 40 +++++++++---------- tests/Core/AbstractFunctionnalTest.php | 2 +- 11 files changed, 40 insertions(+), 39 deletions(-) diff --git a/.php_cs b/.php_cs index 8ad0408d..acd8b667 100644 --- a/.php_cs +++ b/.php_cs @@ -19,6 +19,7 @@ $config = PhpCsFixer\Config::create() 'header_comment' => ['header' => $header], 'linebreak_after_opening_tag' => true, 'modernize_types_casting' => true, + 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'], 'no_superfluous_elseif' => true, 'no_useless_else' => true, 'phpdoc_order' => true, diff --git a/src/Cli/Command/AbstractCommand.php b/src/Cli/Command/AbstractCommand.php index 2fe470cb..928b5061 100644 --- a/src/Cli/Command/AbstractCommand.php +++ b/src/Cli/Command/AbstractCommand.php @@ -50,12 +50,12 @@ abstract class AbstractCommand extends Command implements LoggerInterface protected $output; /** - * @var null|array + * @var array|null */ private $configuration; /** - * @var null|ContainerBuilder + * @var ContainerBuilder|null */ private $container; diff --git a/src/Cli/Command/Helper/KeyOptionCommandTrait.php b/src/Cli/Command/Helper/KeyOptionCommandTrait.php index 4b1c4438..3a2edc31 100644 --- a/src/Cli/Command/Helper/KeyOptionCommandTrait.php +++ b/src/Cli/Command/Helper/KeyOptionCommandTrait.php @@ -21,13 +21,13 @@ trait KeyOptionCommandTrait { private function createKeyOption($keyType) { - switch (\strtoupper($keyType)) { + switch (strtoupper($keyType)) { case 'RSA': return new RsaKeyOption(); case 'EC': return new EcKeyOption(); default: - throw new \InvalidArgumentException(sprintf('The keyType "%s" is not valid. Supported types are: RSA, EC', \strtoupper($keyType))); + throw new \InvalidArgumentException(sprintf('The keyType "%s" is not valid. Supported types are: RSA, EC', strtoupper($keyType))); } } } diff --git a/src/Cli/Configuration/AcmeConfiguration.php b/src/Cli/Configuration/AcmeConfiguration.php index 6b81778c..3f622a8e 100644 --- a/src/Cli/Configuration/AcmeConfiguration.php +++ b/src/Cli/Configuration/AcmeConfiguration.php @@ -26,7 +26,7 @@ class AcmeConfiguration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('acmephp'); - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = $treeBuilder->getRootNode(); } else { $rootNode = $treeBuilder->root('acmephp'); @@ -60,7 +60,7 @@ protected function createRootNode(ArrayNodeDefinition $rootNode) ->cannotBeEmpty() ->validate() ->ifTrue(function ($action) { - return !array_key_exists('action', $action); + return !\array_key_exists('action', $action); }) ->thenInvalid('The "action" configuration key is required.') ->end() diff --git a/src/Cli/Configuration/DomainConfiguration.php b/src/Cli/Configuration/DomainConfiguration.php index b89e36a5..717551ce 100644 --- a/src/Cli/Configuration/DomainConfiguration.php +++ b/src/Cli/Configuration/DomainConfiguration.php @@ -25,7 +25,7 @@ class DomainConfiguration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('acmephp'); - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = $treeBuilder->getRootNode(); } else { $rootNode = $treeBuilder->root('acmephp'); @@ -62,7 +62,7 @@ public function getConfigTreeBuilder() ->beforeNormalization() ->ifString() ->then(function ($conf) { - return \strtoupper($conf); + return strtoupper($conf); }) ->end() ->validate() @@ -81,7 +81,7 @@ public function getConfigTreeBuilder() private function createDefaultsSection() { - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = (new TreeBuilder('defaults'))->getRootNode(); } else { $rootNode = (new TreeBuilder())->root('defaults'); @@ -108,7 +108,7 @@ private function createDefaultsSection() private function createSolverSection() { - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = (new TreeBuilder('solver'))->getRootNode(); } else { $rootNode = (new TreeBuilder())->root('solver'); @@ -128,7 +128,7 @@ private function createSolverSection() private function createDistinguishedNameSection() { - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = (new TreeBuilder('distinguished_name'))->getRootNode(); } else { $rootNode = (new TreeBuilder())->root('distinguished_name'); @@ -179,7 +179,7 @@ private function createDistinguishedNameSection() private function createCertificatesSection() { - if (\method_exists(TreeBuilder::class, 'getRootNode')) { + if (method_exists(TreeBuilder::class, 'getRootNode')) { $rootNode = (new TreeBuilder('certificates'))->getRootNode(); } else { $rootNode = (new TreeBuilder())->root('certificates'); diff --git a/src/Core/Challenge/Dns/LibDnsResolver.php b/src/Core/Challenge/Dns/LibDnsResolver.php index 869abdd5..6417b589 100644 --- a/src/Core/Challenge/Dns/LibDnsResolver.php +++ b/src/Core/Challenge/Dns/LibDnsResolver.php @@ -86,7 +86,7 @@ public static function isSupported() */ public function getTxtEntries($domain) { - $domain = \rtrim($domain, '.'); + $domain = rtrim($domain, '.'); $nameServers = $this->getNameServers($domain); $this->logger->debug('Fetched TXT records for domain', ['nsDomain' => $domain, 'servers' => $nameServers]); $identicalEntries = []; @@ -158,7 +158,7 @@ private function getNameServers($domain) } } } - $itemNameServers = \array_unique($itemNameServers); + $itemNameServers = array_unique($itemNameServers); if (empty($itemNameServers)) { return $parentNameServers; } diff --git a/src/Core/Challenge/Dns/Route53Solver.php b/src/Core/Challenge/Dns/Route53Solver.php index cf98a886..9486715d 100644 --- a/src/Core/Challenge/Dns/Route53Solver.php +++ b/src/Core/Challenge/Dns/Route53Solver.php @@ -180,7 +180,7 @@ function ($recordSet) use ($recordName) { $recordIndex = []; foreach ($recordSets as $previousRecordSet) { $previousTxt = array_map(function ($resourceRecord) { - return \stripslashes(trim($resourceRecord['Value'], '"')); + return stripslashes(trim($resourceRecord['Value'], '"')); }, $previousRecordSet['ResourceRecords']); // Search the special Index foreach ($previousTxt as $index => $recordValue) { @@ -211,7 +211,7 @@ private function getSaveRecordQuery($recordName, array $recordIndex) } } - $recordValues = \array_keys($recordIndex); + $recordValues = array_keys($recordIndex); $recordValues[] = json_encode($recordIndex); return [ diff --git a/src/Core/Http/SecureHttpClient.php b/src/Core/Http/SecureHttpClient.php index 68d0da96..07f35d13 100644 --- a/src/Core/Http/SecureHttpClient.php +++ b/src/Core/Http/SecureHttpClient.php @@ -161,7 +161,7 @@ private function getAlg() private function extractSignOptionFromJWSAlg($alg) { - if (!\preg_match('/^([A-Z]+)(\d+)$/', $alg, $match)) { + if (!preg_match('/^([A-Z]+)(\d+)$/', $alg, $match)) { throw new AcmeCoreClientException(sprintf('The given "%s" algorithm is not supported', $alg)); } diff --git a/src/Core/Util/JsonDecoder.php b/src/Core/Util/JsonDecoder.php index a6516299..77c8bd9a 100644 --- a/src/Core/Util/JsonDecoder.php +++ b/src/Core/Util/JsonDecoder.php @@ -38,7 +38,7 @@ class JsonDecoder */ public static function decode($json, $assoc = false, $depth = 512, $options = 0) { - $data = \json_decode($json, $assoc, $depth, $options); + $data = json_decode($json, $assoc, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) { throw new \InvalidArgumentException('json_decode error: '.json_last_error_msg()); diff --git a/src/Ssl/Signer/DataSigner.php b/src/Ssl/Signer/DataSigner.php index fb649c25..0942efa2 100644 --- a/src/Ssl/Signer/DataSigner.php +++ b/src/Ssl/Signer/DataSigner.php @@ -72,32 +72,32 @@ public function signData($data, PrivateKey $privateKey, $algorithm = OPENSSL_ALG */ private function DERtoECDSA($der, $partLength) { - $hex = \unpack('H*', $der)[1]; - if ('30' !== \mb_substr($hex, 0, 2, '8bit')) { // SEQUENCE + $hex = unpack('H*', $der)[1]; + if ('30' !== mb_substr($hex, 0, 2, '8bit')) { // SEQUENCE throw new DataSigningException('Invalid signature provided'); } - if ('81' === \mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128 - $hex = \mb_substr($hex, 6, null, '8bit'); + if ('81' === mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128 + $hex = mb_substr($hex, 6, null, '8bit'); } else { - $hex = \mb_substr($hex, 4, null, '8bit'); + $hex = mb_substr($hex, 4, null, '8bit'); } - if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER + if ('02' !== mb_substr($hex, 0, 2, '8bit')) { // INTEGER throw new DataSigningException('Invalid signature provided'); } - $Rl = \hexdec(\mb_substr($hex, 2, 2, '8bit')); - $R = $this->retrievePositiveInteger(\mb_substr($hex, 4, $Rl * 2, '8bit')); - $R = \str_pad($R, $partLength, '0', STR_PAD_LEFT); + $Rl = hexdec(mb_substr($hex, 2, 2, '8bit')); + $R = $this->retrievePositiveInteger(mb_substr($hex, 4, $Rl * 2, '8bit')); + $R = str_pad($R, $partLength, '0', STR_PAD_LEFT); - $hex = \mb_substr($hex, 4 + $Rl * 2, null, '8bit'); - if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER + $hex = mb_substr($hex, 4 + $Rl * 2, null, '8bit'); + if ('02' !== mb_substr($hex, 0, 2, '8bit')) { // INTEGER throw new DataSigningException('Invalid signature provided'); } - $Sl = \hexdec(\mb_substr($hex, 2, 2, '8bit')); - $S = $this->retrievePositiveInteger(\mb_substr($hex, 4, $Sl * 2, '8bit')); - $S = \str_pad($S, $partLength, '0', STR_PAD_LEFT); + $Sl = hexdec(mb_substr($hex, 2, 2, '8bit')); + $S = $this->retrievePositiveInteger(mb_substr($hex, 4, $Sl * 2, '8bit')); + $S = str_pad($S, $partLength, '0', STR_PAD_LEFT); - return \pack('H*', $R.$S); + return pack('H*', $R.$S); } /** @@ -107,11 +107,11 @@ private function DERtoECDSA($der, $partLength) */ private function preparePositiveInteger($data) { - if (\mb_substr($data, 0, 2, '8bit') > '7f') { + if (mb_substr($data, 0, 2, '8bit') > '7f') { return '00'.$data; } - while ('00' === \mb_substr($data, 0, 2, '8bit') && \mb_substr($data, 2, 2, '8bit') <= '7f') { - $data = \mb_substr($data, 2, null, '8bit'); + while ('00' === mb_substr($data, 0, 2, '8bit') && mb_substr($data, 2, 2, '8bit') <= '7f') { + $data = mb_substr($data, 2, null, '8bit'); } return $data; @@ -124,8 +124,8 @@ private function preparePositiveInteger($data) */ private function retrievePositiveInteger($data) { - while ('00' === \mb_substr($data, 0, 2, '8bit') && \mb_substr($data, 2, 2, '8bit') > '7f') { - $data = \mb_substr($data, 2, null, '8bit'); + while ('00' === mb_substr($data, 0, 2, '8bit') && mb_substr($data, 2, 2, '8bit') > '7f') { + $data = mb_substr($data, 2, null, '8bit'); } return $data; diff --git a/tests/Core/AbstractFunctionnalTest.php b/tests/Core/AbstractFunctionnalTest.php index a8a2a13e..d12eab46 100644 --- a/tests/Core/AbstractFunctionnalTest.php +++ b/tests/Core/AbstractFunctionnalTest.php @@ -46,7 +46,7 @@ protected function createServerProcess($token, $payload) '"'.$documentRoot.'"', ]); - if (\method_exists(Process::class, 'fromShellCommandline')) { + if (method_exists(Process::class, 'fromShellCommandline')) { return Process::fromShellCommandline('exec '.$script, $documentRoot, null, null, null); }