diff --git a/README.md b/README.md index 24479bf..5631db3 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ $driver = $container[IPFS\Driver\Cli::class]; //$driver = $container[IPFS\Driver\Http::class]; $client = new IPFS\Client($driver); -$reponse = $client->execute((new \IPFS\Api\Basics())->version()); +$response = $client->execute((new \IPFS\Api\Basics())->version()); var_dump($response); ``` diff --git a/src/Command/Command.php b/src/Command/Command.php index 31fa342..812b76a 100644 --- a/src/Command/Command.php +++ b/src/Command/Command.php @@ -37,7 +37,13 @@ public function getAction(): string $parts = explode('\\', $this->method); $shortName = array_pop($parts); - return CaseFormatter::camelToColon(str_replace('::', ':', $shortName)); + $name = CaseFormatter::camelToColon(str_replace('::', ':', $shortName)); + + // correct some naming workaround due to reserved keywords + $name = str_replace('basics:', '', $name); + $name = str_replace('cobject:', 'object:', $name); + + return $name; } public function getArguments(): array diff --git a/src/Driver/Cli.php b/src/Driver/Cli.php index 1824f6a..1799e65 100644 --- a/src/Driver/Cli.php +++ b/src/Driver/Cli.php @@ -62,7 +62,7 @@ private function buildCommand(Command $command): array { return array_merge( [$this->binary], - explode(':', str_replace('basics:', '', $command->getAction())), + explode(':', $command->getAction()), $this->parseParameters($command) ); } diff --git a/tests/spec/Command/CommandSpec.php b/tests/spec/Command/CommandSpec.php index 36a25be..f58465f 100644 --- a/tests/spec/Command/CommandSpec.php +++ b/tests/spec/Command/CommandSpec.php @@ -36,4 +36,18 @@ public function it_can_convert_the_method_to_an_action() { $this->getAction()->shouldBe('command:spec:foo:bar:bazz'); } + + public function it_will_revert_reserved_keywords_workaround() + { + $this->beConstructedWith('cobject' . '::fooBarBazz'); + + $this->getAction()->shouldBe('object:foo:bar:bazz'); + } + + public function it_will_strip_basic_commands() + { + $this->beConstructedWith('basics' . '::fooBarBazz'); + + $this->getAction()->shouldBe('foo:bar:bazz'); + } }