From 7a30cbe180e9dc39febd9d14fa90652b7bbc4e9c Mon Sep 17 00:00:00 2001 From: nmeri17 Date: Tue, 25 Apr 2023 13:12:09 +0100 Subject: [PATCH] Run project through psr-12 --- .php_cs.php | 14 +++ AllModules/PublishedModules.php | 21 ++-- .../_module_name/Config/RouterMock.php | 19 +-- .../Coordinators/BaseCoordinator.php | 17 +-- .../Markup/components/AppLayout.php | 24 ++-- .../Meta/CustomInterfaceCollection.php | 44 +++---- .../_module_name/Meta/ModuleApi.php | 12 +- .../Meta/_module_nameDescriptor.php | 67 +++++----- .../_module_name/Routes/BrowserCollection.php | 30 ++--- .../_module_name/Tests/ConfirmInstallTest.php | 34 ++--- .../Exceptions/DisgracefulShutdownTest.php | 117 +++++++++--------- .../Tests/Exceptions/GracefulShutdownTest.php | 45 +++---- .../Tests/Exceptions/ServerBuildTest.php | 32 ++--- .../ModuleInteractions/_module_name.php | 10 +- manual-flow-starter.php | 26 ++-- public/index.php | 14 +-- suphle-worker.php | 18 +-- 17 files changed, 289 insertions(+), 255 deletions(-) create mode 100644 .php_cs.php diff --git a/.php_cs.php b/.php_cs.php new file mode 100644 index 0000000..1d4331d --- /dev/null +++ b/.php_cs.php @@ -0,0 +1,14 @@ +in(__DIR__); + + $config = new PhpCsFixer\Config(); + $config + ->setRules([ + "@PSR12" => true + ]) + ->setFinder($finder); + + return $config; +?> \ No newline at end of file diff --git a/AllModules/PublishedModules.php b/AllModules/PublishedModules.php index 1e791af..18eb0f6 100644 --- a/AllModules/PublishedModules.php +++ b/AllModules/PublishedModules.php @@ -1,15 +1,16 @@ \ No newline at end of file +class PublishedModules extends ModuleHandlerIdentifier +{ + public function getModules(): array + { + + return []; + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Config/RouterMock.php b/ModuleTemplate/AllModules/_module_name/Config/RouterMock.php index 74eac8b..d847450 100644 --- a/ModuleTemplate/AllModules/_module_name/Config/RouterMock.php +++ b/ModuleTemplate/AllModules/_module_name/Config/RouterMock.php @@ -1,15 +1,16 @@ \ No newline at end of file + return BrowserCollection::class; + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Coordinators/BaseCoordinator.php b/ModuleTemplate/AllModules/_module_name/Coordinators/BaseCoordinator.php index c4bf719..7cc11af 100644 --- a/ModuleTemplate/AllModules/_module_name/Coordinators/BaseCoordinator.php +++ b/ModuleTemplate/AllModules/_module_name/Coordinators/BaseCoordinator.php @@ -1,13 +1,14 @@ "World"]; - } - } -?> \ No newline at end of file + return ["message" => "World"]; + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Markup/components/AppLayout.php b/ModuleTemplate/AllModules/_module_name/Markup/components/AppLayout.php index d106161..fc567c3 100644 --- a/ModuleTemplate/AllModules/_module_name/Markup/components/AppLayout.php +++ b/ModuleTemplate/AllModules/_module_name/Markup/components/AppLayout.php @@ -1,18 +1,20 @@ \ No newline at end of file + return view("layouts.app"); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Meta/CustomInterfaceCollection.php b/ModuleTemplate/AllModules/_module_name/Meta/CustomInterfaceCollection.php index 3936ebe..2b5832f 100644 --- a/ModuleTemplate/AllModules/_module_name/Meta/CustomInterfaceCollection.php +++ b/ModuleTemplate/AllModules/_module_name/Meta/CustomInterfaceCollection.php @@ -1,34 +1,36 @@ RouterMock::class - ]); - } + return array_merge(parent::getConfigs(), [ - public function simpleBinds ():array { + Router::class => RouterMock::class + ]); + } - return array_merge(parent::simpleBinds(), [ + public function simpleBinds(): array + { - _module_name::class => ModuleApi::class, + return array_merge(parent::simpleBinds(), [ - UserContract::class => EloquentUser::class - ]); - } - } -?> \ No newline at end of file + _module_name::class => ModuleApi::class, + + UserContract::class => EloquentUser::class + ]); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Meta/ModuleApi.php b/ModuleTemplate/AllModules/_module_name/Meta/ModuleApi.php index 47f7d8a..1f9a19a 100644 --- a/ModuleTemplate/AllModules/_module_name/Meta/ModuleApi.php +++ b/ModuleTemplate/AllModules/_module_name/Meta/ModuleApi.php @@ -1,10 +1,10 @@ \ No newline at end of file +class ModuleApi implements _module_name +{ + // +} diff --git a/ModuleTemplate/AllModules/_module_name/Meta/_module_nameDescriptor.php b/ModuleTemplate/AllModules/_module_name/Meta/_module_nameDescriptor.php index 34b77c7..31d02c9 100644 --- a/ModuleTemplate/AllModules/_module_name/Meta/_module_nameDescriptor.php +++ b/ModuleTemplate/AllModules/_module_name/Meta/_module_nameDescriptor.php @@ -1,49 +1,52 @@ new AscendingHierarchy( - - __DIR__, __NAMESPACE__, + ModuleFiles::class => new AscendingHierarchy( + __DIR__, + __NAMESPACE__, + $this->container->getClass(FileSystemReader::class) + ) + ]); + } - $this->container->getClass(FileSystemReader::class) - ) - ]); - } + /** + * Remove this method after installation completes. Without components, the illuminate component won't boot and interrupt module creation + */ + protected function registerConcreteBindings(): void + { - /** - * Remove this method after installation completes. Without components, the illuminate component won't boot and interrupt module creation - */ - protected function registerConcreteBindings ():void { + $bindings = $this->globalConcretes(); - $bindings = $this->globalConcretes(); - - $this->container->whenTypeAny()->needsAny($bindings); - } - } -?> \ No newline at end of file + $this->container->whenTypeAny()->needsAny($bindings); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Routes/BrowserCollection.php b/ModuleTemplate/AllModules/_module_name/Routes/BrowserCollection.php index 2214bd6..18c933c 100644 --- a/ModuleTemplate/AllModules/_module_name/Routes/BrowserCollection.php +++ b/ModuleTemplate/AllModules/_module_name/Routes/BrowserCollection.php @@ -1,23 +1,25 @@ _get(new Json("handleHello")); - } - } -?> \ No newline at end of file + $this->_get(new Json("handleHello")); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Tests/ConfirmInstallTest.php b/ModuleTemplate/AllModules/_module_name/Tests/ConfirmInstallTest.php index 42ce76e..6baea2d 100644 --- a/ModuleTemplate/AllModules/_module_name/Tests/ConfirmInstallTest.php +++ b/ModuleTemplate/AllModules/_module_name/Tests/ConfirmInstallTest.php @@ -1,27 +1,29 @@ get("/$prefix/hello") // when + $this->get("/$prefix/hello") // when - // then - ->assertOk()->assertJson(["message" => "World"]); - } - } -?> \ No newline at end of file + // then + ->assertOk()->assertJson(["message" => "World"]); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/DisgracefulShutdownTest.php b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/DisgracefulShutdownTest.php index 48d14cf..2233c7f 100644 --- a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/DisgracefulShutdownTest.php +++ b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/DisgracefulShutdownTest.php @@ -1,91 +1,94 @@ getContainer()->getMethodParameters( + $parameters = $this->getContainer()->getMethodParameters( + Container::CLASS_CONSTRUCTOR, + self::BRIDGE_NAME + ); - Container::CLASS_CONSTRUCTOR, self::BRIDGE_NAME - ); + $this->exceptionConfig = $parameters["config"] = $this->stubExceptionConfig(); - $this->exceptionConfig = $parameters["config"] = $this->stubExceptionConfig(); + $defaultStubs = [ - $defaultStubs = [ + "writeStatusCode" => null + ]; - "writeStatusCode" => null - ]; + $this->massProvide([ - $this->massProvide([ + self::BRIDGE_NAME => $this->replaceConstructorArguments( + self::BRIDGE_NAME, + $parameters, + array_merge($defaultStubs, $stubMethods), // overridding the method since parent can only make provision for merge and not unset (of disgracefulShutdown stub) - self::BRIDGE_NAME => $this->replaceConstructorArguments( + $mockMethods + ) + ]); + } - self::BRIDGE_NAME, $parameters, + protected function stubExceptionConfig(): ExceptionInterceptor + { - array_merge($defaultStubs, $stubMethods), // overridding the method since parent can only make provision for merge and not unset (of disgracefulShutdown stub) + return $this->positiveDouble(ExceptionInterceptor::class, [ - $mockMethods - ) - ]); - } + "shutdownLog" => "error-log.txt", - protected function stubExceptionConfig ():ExceptionInterceptor { + "shutdownText" => "Bye World" + ]); + } - return $this->positiveDouble(ExceptionInterceptor::class, [ + public function test_disgraceful_shutdown_successful() + { - "shutdownLog" => "error-log.txt", + // given + $logPath = $this->exceptionConfig->shutdownLog(); - "shutdownText" => "Bye World" - ]); - } + $this->assertEmptyDirectory($logPath); - public function test_disgraceful_shutdown_successful () { + $exception = new Exception(); - // given - $logPath = $this->exceptionConfig->shutdownLog(); + $exceptionDetails = \Wyrihaximus\throwable_json_encode($exception); - $this->assertEmptyDirectory($logPath); + // when + $response = $this->getContainer()->getClass(self::BRIDGE_NAME) - $exception = new Exception; + ->disgracefulShutdown($exceptionDetails, $exception); - $exceptionDetails = \Wyrihaximus\throwable_json_encode($exception); + // then + $this->assertFileExists($logPath); - // when - $response = $this->getContainer()->getClass(self::BRIDGE_NAME) + $this->assertStringContainsStringIgnoringCase($exceptionDetails); - ->disgracefulShutdown($exceptionDetails, $exception); + $this->assertNotEmptyDirectory($logPath, true); - // then - $this->assertFileExists($logPath); - - $this->assertStringContainsStringIgnoringCase($exceptionDetails); - - $this->assertNotEmptyDirectory($logPath, true); - - $this->assertSame( - - $response, $this->exceptionConfig->shutdownText() - ); - } - } -?> \ No newline at end of file + $this->assertSame( + $response, + $this->exceptionConfig->shutdownText() + ); + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/GracefulShutdownTest.php b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/GracefulShutdownTest.php index 6529d45..9e1f655 100644 --- a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/GracefulShutdownTest.php +++ b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/GracefulShutdownTest.php @@ -1,37 +1,38 @@ getContainer()->getClass(self::BRIDGE_NAME) + $renderer = $this->getContainer()->getClass(self::BRIDGE_NAME) - ->gracefulShutdown($exceptionDetails); // when + ->gracefulShutdown($exceptionDetails); // when - $this->assertTrue( - - $renderer->matchesHandler(GenericDiffuser::CONTROLLER_ACTION) - ); // then - } - } -?> \ No newline at end of file + $this->assertTrue( + $renderer->matchesHandler(GenericDiffuser::CONTROLLER_ACTION) + ); // then + } +} diff --git a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/ServerBuildTest.php b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/ServerBuildTest.php index 2b06fcf..54316f1 100644 --- a/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/ServerBuildTest.php +++ b/ModuleTemplate/AllModules/_module_name/Tests/Exceptions/ServerBuildTest.php @@ -1,26 +1,28 @@ assertServerBuilds(); - } - } -?> \ No newline at end of file + $this->assertServerBuilds(); + } +} diff --git a/ModuleTemplate/ModuleInteractions/_module_name.php b/ModuleTemplate/ModuleInteractions/_module_name.php index a50b14c..257f931 100644 --- a/ModuleTemplate/ModuleInteractions/_module_name.php +++ b/ModuleTemplate/ModuleInteractions/_module_name.php @@ -1,8 +1,8 @@ \ No newline at end of file +interface _module_name +{ + // +} diff --git a/manual-flow-starter.php b/manual-flow-starter.php index 65f0623..3c38ae6 100644 --- a/manual-flow-starter.php +++ b/manual-flow-starter.php @@ -1,22 +1,22 @@ buildIdentifier(); +$accessor = (new ModuleWorkerAccessor($handlerIdentifier, false)) - $handlerIdentifier->firstContainer()->getClass(OuterFlowWrapper::class); // should trigger queue server setup +->buildIdentifier(); - $accessor->getQueueWorker()->processTasks(); -?> \ No newline at end of file +$handlerIdentifier->firstContainer()->getClass(OuterFlowWrapper::class); // should trigger queue server setup + +$accessor->getQueueWorker()->processTasks(); diff --git a/public/index.php b/public/index.php index d65eb7f..25500fe 100644 --- a/public/index.php +++ b/public/index.php @@ -1,13 +1,13 @@ buildIdentifier()->getRequestRenderer($_GET["suphle_path"], true) +echo (new ModuleWorkerAccessor(new PublishedModules(), true)) - ->render(); -?> \ No newline at end of file +->buildIdentifier()->getRequestRenderer($_GET["suphle_path"], true) + +->render(); diff --git a/suphle-worker.php b/suphle-worker.php index 1385df7..fe44f3f 100644 --- a/suphle-worker.php +++ b/suphle-worker.php @@ -1,17 +1,17 @@ getMode() === Mode::MODE_HTTP; +$publishedModules = new PublishedModules(); - (new ModuleWorkerAccessor($publishedModules, $isHttpMode)) +$isHttpMode = Environment::fromGlobals()->getMode() === Mode::MODE_HTTP; - ->safeSetupWorker(); -?> \ No newline at end of file +(new ModuleWorkerAccessor($publishedModules, $isHttpMode)) + +->safeSetupWorker();