Skip to content

Commit

Permalink
Ran php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
mcustiel committed Feb 19, 2021
1 parent 92d4e40 commit 2d88148
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bin/phiremock.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const IS_SINGLE_COMMAND = true;

if (PHP_SAPI !== 'cli') {
if (\PHP_SAPI !== 'cli') {
throw new RuntimeException('This is a standalone CLI application');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Actions/ActionLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(ActionsFactory $factory)

public function locate(string $actionIdentifier): ActionInterface
{
if (array_key_exists($actionIdentifier, self::ACTION_FACTORY_METHOD_MAP)) {
if (\array_key_exists($actionIdentifier, self::ACTION_FACTORY_METHOD_MAP)) {
return $this->factory->{self::ACTION_FACTORY_METHOD_MAP[$actionIdentifier]}();
}
throw new InvalidArgumentException(sprintf('Trying to get action using %s. Which is not a valid action name.', var_export($actionIdentifier, true)));
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/ListRequestsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function execute(ServerRequestInterface $request, ResponseInterface $resp
public function process(ResponseInterface $response, Expectation $expectation): ResponseInterface
{
$executions = $this->searchForExecutionsCount($expectation);
$this->logger->debug('Listed ' . count($executions) . ' request matching the expectation');
$this->logger->debug('Listed ' . \count($executions) . ' request matching the expectation');

return $response
->withStatus(200)
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/SetScenarioStateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function parseJsonBody(ServerRequestInterface $request): array
}

$bodyJson = @json_decode($body, true);
if (JSON_ERROR_NONE !== json_last_error()) {
if (\JSON_ERROR_NONE !== json_last_error()) {
throw new \Exception(json_last_error_msg());
}

Expand Down
56 changes: 27 additions & 29 deletions src/Cli/Commands/PhiremockServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,37 @@ protected function configure(): void
'debug',
'd',
InputOption::VALUE_NONE,
sprintf(self::DEBUG_HELP_MESSAGE)
self::DEBUG_HELP_MESSAGE
)
->addOption(
'config-path',
'c',
InputOption::VALUE_REQUIRED,
sprintf(self::CONFIG_PATH_HELP_MESSAGE)
self::CONFIG_PATH_HELP_MESSAGE
)
->addOption(
'factory-class',
'f',
InputOption::VALUE_REQUIRED,
sprintf(self::FACTORY_CLASS_HELP_MESSAGE)
self::FACTORY_CLASS_HELP_MESSAGE
)
->addOption(
'certificate',
't',
InputOption::VALUE_REQUIRED,
sprintf(self::CERTIFICATE_HELP_MESSAGE)
self::CERTIFICATE_HELP_MESSAGE
)
->addOption(
'certificate-key',
'k',
InputOption::VALUE_REQUIRED,
sprintf(self::CERTIFICATE_KEY_HELP_MESSAGE)
self::CERTIFICATE_KEY_HELP_MESSAGE
)
->addOption(
'cert-passphrase',
's',
InputOption::VALUE_REQUIRED,
sprintf(self::PASSPHRASE_HELP_MESSAGE)
self::PASSPHRASE_HELP_MESSAGE
);
}

Expand All @@ -133,6 +133,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

protected function getConfigPath(InputInterface $input): ?Directory
{
$configPath = null;
$configPathOptionValue = $input->getOption('config-path');
if ($configPathOptionValue) {
$configPath = new Directory($configPathOptionValue);
}

return $configPath;
}

/** @throws Exception */
private function createPhiremockPathIfNotExists(): void
{
Expand Down Expand Up @@ -190,9 +201,9 @@ private function setUpHandlers(): void
$this->logger->debug('Registering shutdown function');
register_shutdown_function($handleTermination);

if (function_exists('pcntl_signal')) {
if (\function_exists('pcntl_signal')) {
$this->logger->debug('PCNTL present: Installing signal handlers');
pcntl_signal(SIGTERM, function () { exit(0); });
pcntl_signal(\SIGTERM, function () { exit(0); });
}

$errorHandler = function ($severity, $message, $file, $line) {
Expand All @@ -210,14 +221,14 @@ private function setUpHandlers(): void

private function isError(int $severity): bool
{
return in_array(
return \in_array(
$severity,
[
E_COMPILE_ERROR,
E_CORE_ERROR,
E_USER_ERROR,
E_PARSE,
E_ERROR,
\E_COMPILE_ERROR,
\E_CORE_ERROR,
\E_USER_ERROR,
\E_PARSE,
\E_ERROR,
],
true
);
Expand All @@ -230,23 +241,10 @@ private function getCommandLineOptions(InputInterface $input): array
foreach (Config::CONFIG_OPTIONS as $configOption) {
$optionValue = $input->getOption($configOption);
if ($optionValue) {
$cliConfig[$configOption] = (string)$optionValue;
$cliConfig[$configOption] = (string) $optionValue;
}
}
return $cliConfig;
}

/**
* @param InputInterface $input
* @return Directory|null
*/
protected function getConfigPath(InputInterface $input): ?Directory
{
$configPath = null;
$configPathOptionValue = $input->getOption('config-path');
if ($configPathOptionValue) {
$configPath = new Directory($configPathOptionValue);
}
return $configPath;
return $cliConfig;
}
}
2 changes: 1 addition & 1 deletion src/Factory/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function createLogger(): LoggerInterface
if (!$this->factoryCache->has('logger')) {
$logger = new Logger('stdoutLogger');
$logLevel = $this->config->isDebugMode() ? Logger::DEBUG : Logger::INFO;
$logger->pushHandler(new StreamHandler(STDOUT, $logLevel));
$logger->pushHandler(new StreamHandler(\STDOUT, $logLevel));
$this->factoryCache->set('logger', $logger);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Http/Implementation/FastRouterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use function FastRoute\simpleDispatcher;
use Laminas\Diactoros\Response;
use Mcustiel\Phiremock\Common\StringStream;
use Mcustiel\Phiremock\Server\Actions\ActionLocator;
Expand All @@ -29,7 +30,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Throwable;
use function FastRoute\simpleDispatcher;

class FastRouterHandler implements RequestHandlerInterface
{
Expand Down Expand Up @@ -77,6 +77,7 @@ public function dispatch(ServerRequestInterface $request): ResponseInterface
->locate($routeInfo[1])
->execute($request, new Response());
}

return new Response(
new StringStream(
json_encode(['result' => 'ERROR', 'details' => 'Unexpected error: Router returned unexpected info'])
Expand Down
10 changes: 5 additions & 5 deletions src/Utils/ArraysHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static function isAssociative(array $array): bool
return false;
}

return array_keys($array) !== range(0, count($array) - 1);
return array_keys($array) !== range(0, \count($array) - 1);
}

public static function areRecursivelyEquals(array $array1, array $array2): bool
{
if (count($array1) !== count($array2)) {
if (\count($array1) !== \count($array2)) {
return false;
}

Expand All @@ -41,7 +41,7 @@ public static function areRecursivelyEquals(array $array1, array $array2): bool
public static function arrayIsContained(array $array1, array $array2): bool
{
foreach ($array1 as $key => $value1) {
if (!array_key_exists($key, $array2)) {
if (!\array_key_exists($key, $array2)) {
return false;
}
if (!self::haveTheSameTypeAndValue($value1, $array2[$key])) {
Expand All @@ -54,7 +54,7 @@ public static function arrayIsContained(array $array1, array $array2): bool

public static function haveTheSameTypeAndValue($value1, $value2): bool
{
if (gettype($value1) !== gettype($value2)) {
if (\gettype($value1) !== \gettype($value2)) {
return false;
}

Expand All @@ -63,7 +63,7 @@ public static function haveTheSameTypeAndValue($value1, $value2): bool

public static function haveTheSameValue($value1, $value2): bool
{
if (is_array($value1)) {
if (\is_array($value1)) {
if (!self::areRecursivelyEquals($value1, $value2)) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Utils/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function getDefaultExpectationsDir(): ExpectationsDirectory
{
return new ExpectationsDirectory(
HomePathService::getHomePath()->getFullSubpathAsString(
'.phiremock' . DIRECTORY_SEPARATOR . 'expectations'
'.phiremock' . \DIRECTORY_SEPARATOR . 'expectations'
)
);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ protected function searchFileAndGetConfig(): array
getcwd() . '/.phiremock',
getcwd() . '/.phiremock.dist',
HomePathService::getHomePath()->getFullSubpathAsString(
'.phiremock' . DIRECTORY_SEPARATOR . 'config'
'.phiremock' . \DIRECTORY_SEPARATOR . 'config'
),
'.phiremock',
'.phiremock.dist',
Expand All @@ -112,6 +112,7 @@ protected function searchFileAndGetConfig(): array
return require $configFilePath;
}
}

return [];
}
}
4 changes: 2 additions & 2 deletions src/Utils/Config/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Directory
public function __construct(string $directory)
{
$this->ensureIsDirectory($directory);
$this->directory = rtrim($directory, DIRECTORY_SEPARATOR);
$this->directory = rtrim($directory, \DIRECTORY_SEPARATOR);
}

public function asString(): string
Expand All @@ -39,7 +39,7 @@ public function asString(): string

public function getFullSubpathAsString(string $subPath): string
{
return $this->directory . DIRECTORY_SEPARATOR . $subPath;
return $this->directory . \DIRECTORY_SEPARATOR . $subPath;
}

private function ensureIsDirectory(string $directory): void
Expand Down
12 changes: 6 additions & 6 deletions src/Utils/DataStructures/StringObjectArrayMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function getIterator()

public function set($key, $value)
{
if (!is_string($key)) {
throw new InvalidArgumentException('Expected key to be string. Got: ' . gettype($key));
if (!\is_string($key)) {
throw new InvalidArgumentException('Expected key to be string. Got: ' . \gettype($key));
}

if (!is_object($value)) {
throw new InvalidArgumentException('Expected value to be object. Got: ' . gettype($key));
if (!\is_object($value)) {
throw new InvalidArgumentException('Expected value to be object. Got: ' . \gettype($key));
}
$this->mapData[$key] = $value;
}
Expand All @@ -59,8 +59,8 @@ public function get($key)

public function has($key)
{
if (!is_string($key)) {
throw new InvalidArgumentException('Expected key to be string. Got: ' . gettype($key));
if (!\is_string($key)) {
throw new InvalidArgumentException('Expected key to be string. Got: ' . \gettype($key));
}

return isset($this->mapData[$key]);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/FileExpectationsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function loadExpectationFromFile(string $fileName): void
$this->logger->debug("Loading expectation file $fileName");
$content = file_get_contents($fileName);
$data = @json_decode($content, true);
if (JSON_ERROR_NONE !== json_last_error()) {
if (\JSON_ERROR_NONE !== json_last_error()) {
throw new Exception(json_last_error_msg());
}
$expectation = $this->converterLocator->locate($data)->convert($data);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/RequestToExpectationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function parseJsonBody(ServerRequestInterface $request): array
}

$bodyJson = @json_decode($body, true);
if (JSON_ERROR_NONE !== json_last_error()) {
if (\JSON_ERROR_NONE !== json_last_error()) {
throw new Exception(json_last_error_msg());
}
$this->logger->debug('BODY JSON: ' . var_export($bodyJson, true));
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/_support/Helper/AcceptanceV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getPhiremockRequest(array $request): array
public function getPhiremockResponse(string $jsonResponse): string
{
$parsedExpectations = json_decode($jsonResponse, true);
if (json_last_error() !== JSON_ERROR_NONE) {
if (json_last_error() !== \JSON_ERROR_NONE) {
return $jsonResponse;
}
$v2 = [];
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/v1/BodyConditionCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ public function responseExpectedWhenRequestBodyContainsTest(AcceptanceTester $I)
$I->seeResponseEquals('Found');
}


public function responseExpectedWhenRequestBodyCaseInsensitiveEqualsTest(AcceptanceTester $I)
{
$I->wantTo('see if mocking based in request body case insensitive equality works');
Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/extensions/ServerControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function suiteAfter()
if (!$this->application->isRunning()) {
return;
}
$this->application->stop(5, SIGTERM);
$this->application->stop(5, \SIGTERM);
$this->writeln('Phiremock is stopped');
}
}

0 comments on commit 2d88148

Please sign in to comment.