diff --git a/.gitignore b/.gitignore index 6d1c5b4..6131d86 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ composer.lock .phpunit.result.cache testbench/ -/coverage \ No newline at end of file +/coverage +.DS_Store \ No newline at end of file diff --git a/changelog.md b/changelog.md index a7168d4..8414de7 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,11 @@ All notable changes to `laravel Ussd` will be documented in this file. ## [Unreleased] +## [v2.3.1] - 2021-10-15 + +### Fixed +- Coding style + ## [v2.3.0] - 2021-06-27 ### Added - Add missen test to improve coverage @@ -59,7 +64,8 @@ All notable changes to `laravel Ussd` will be documented in this file. - Ussd config to allow developers customize behaviour - Ussd service Provider class to allow laravel know how to integrate the package -[Unreleased]: ../../compare/v2.3.0...HEAD +[Unreleased]: ../../compare/v2.3.1...HEAD +[v2.3.1]: ../../compare/v2.3.0...v2.3.1 [v2.3.0]: ../../compare/v2.2.0...v2.3.0 [v2.2.0]: ../../compare/v2.1.0...v2.2.0 [v2.1.0]: ../../compare/v2.0.0...v2.1.0 diff --git a/config/ussd.php b/config/ussd.php index 9896af0..f7c24dd 100644 --- a/config/ussd.php +++ b/config/ussd.php @@ -1,7 +1,7 @@ env('USSD_DEFAULT_VALUE', null), -]; \ No newline at end of file +]; diff --git a/readme.md b/readme.md index 39cb8cf..7f980c6 100644 --- a/readme.md +++ b/readme.md @@ -261,7 +261,7 @@ You'll find the documentation on [https://sparors.github.io/ussd-docs](https://s ### Testing ``` bash -$ composer test +$ vendor\bin\phpunit ``` ### Change log diff --git a/src/Action.php b/src/Action.php index 7676ec3..5a3a56a 100644 --- a/src/Action.php +++ b/src/Action.php @@ -8,7 +8,7 @@ abstract class Action /** @var Record */ protected $record; - public abstract function run(): string; + abstract public function run(): string; /** * @param Record $record diff --git a/src/Commands/GenerateCommand.php b/src/Commands/GenerateCommand.php index 904b951..5321d4b 100644 --- a/src/Commands/GenerateCommand.php +++ b/src/Commands/GenerateCommand.php @@ -11,7 +11,7 @@ class GenerateCommand extends Command protected function pathFromNamespace($namespace, $relativePath) { $extended_path = implode('\\', array_map(function ($value) { - return ucfirst($value); + return ucfirst($value); }, explode(DIRECTORY_SEPARATOR, $relativePath))); $base_path = Str::replaceFirst(app()->getNamespace(), '', $namespace); @@ -23,7 +23,7 @@ protected function pathFromNamespace($namespace, $relativePath) protected function classNamespace($namespace, $relativePath) { $path = array_map(function ($value) { - return ucfirst($value); + return ucfirst($value); }, explode(DIRECTORY_SEPARATOR, $relativePath)); array_pop($path); @@ -46,4 +46,4 @@ protected function ensureDirectoryExists($namespace, $relativePath) File::makeDirectory(dirname($path), 0777, $recursive = true, $force = true); } } -} \ No newline at end of file +} diff --git a/src/Facades/Ussd.php b/src/Facades/Ussd.php index cfbf863..2907257 100644 --- a/src/Facades/Ussd.php +++ b/src/Facades/Ussd.php @@ -8,7 +8,7 @@ * @method static \Sparors\Ussd\Record record(string $id, string $store = null) * @method static \Sparors\Ussd\Menu menu(string $menu) * @method static \Sparors\Ussd\Machine machine() - * + * * @see \Sparors\Ussd\Ussd */ class Ussd extends Facade diff --git a/src/HasManipulators.php b/src/HasManipulators.php index d3cefee..09cd825 100644 --- a/src/HasManipulators.php +++ b/src/HasManipulators.php @@ -71,7 +71,7 @@ public function setStore(?string $store) public function set(array $parameters) { - foreach($parameters as $property => $value) { + foreach ($parameters as $property => $value) { $property = Str::camel($property); if (property_exists($this, $property)) { $this->$property = $value; @@ -83,7 +83,7 @@ public function set(array $parameters) public function setFromRequest(array $parameters) { - foreach($parameters as $property => $key) { + foreach ($parameters as $property => $key) { $property = Str::camel($property); if (property_exists($this, $property)) { $this->$property = request($key); @@ -106,7 +106,7 @@ public function setInitialState($state) } else { $this->initialState = null; } - + return $this; } diff --git a/src/Machine.php b/src/Machine.php index 4da795e..cebe8a1 100644 --- a/src/Machine.php +++ b/src/Machine.php @@ -18,7 +18,7 @@ class Machine /** @var Record */ protected $record; - + /** @var string|null */ protected $sessionId; @@ -52,7 +52,7 @@ public function __construct() public function run() { $this->ensureSessionIdIsSet($this->sessionId); - + $this->record = new Record( Cache::store($this->store), $this->sessionId @@ -64,12 +64,12 @@ public function run() $active = $this->record->get('__active'); $this->ensureClassExist( - $active, + $active, 'Active State Class needs to be set before ussd machine can' . ' run. It may be that your session has ended.' ); - $activeClass = new $active; + $activeClass = new $active(); $activeClass->setRecord($this->record); $state = $activeClass->next($this->input); @@ -80,10 +80,9 @@ public function run() 'Continuing State Class needs to be set before ussd ' . 'machine can run. It may be that your session has ended.' ); - + $this->record->set('__active', $state); } else { - $this->processInitialState(); $state = $this->initialState; @@ -154,9 +153,9 @@ protected function processAction(&$stateClass, &$state, $exception): void $this->ensureClassExist( $state, $exception - ); - - $stateClass = new $state; + ); + + $stateClass = new $state(); $stateClass->setRecord($this->record); if (is_subclass_of($stateClass, Action::class)) { @@ -167,7 +166,7 @@ protected function processAction(&$stateClass, &$state, $exception): void 'Ussd Action Class needs to return next State Class' ); - $stateClass = new $state; + $stateClass = new $state(); $stateClass->setRecord($this->record); } } diff --git a/src/Menu.php b/src/Menu.php index adb288d..de1a237 100644 --- a/src/Menu.php +++ b/src/Menu.php @@ -4,24 +4,24 @@ class Menu { - const NUMBERING_ALPHABETIC_LOWER = 'alphabetic_lower'; - const NUMBERING_ALPHABETIC_UPPER = 'alphabetic_upper'; - const NUMBERING_EMPTY = 'empty'; - const NUMBERING_NUMERIC = 'numeric'; - - const ITEMS_SEPARATOR_NO_LINE_BREAK = ""; - const ITEMS_SEPARATOR_LINE_BREAK = "\n"; - const ITEMS_SEPARATOR_DOUBLE_LINE_BREAK = "\n\n"; - - const NUMBERING_SEPARATOR_NO_SPACE = ""; - const NUMBERING_SEPARATOR_SPACE = " "; - const NUMBERING_SEPARATOR_DOUBLE_SPACE = " "; - const NUMBERING_SEPARATOR_DOT = "."; - const NUMBERING_SEPARATOR_DOT_PLUS_SPACE = ". "; - const NUMBERING_SEPARATOR_DOT_PLUS_DOUBLE_SPACE = ". "; - const NUMBERING_SEPARATOR_BRACKET = ")"; - const NUMBERING_SEPARATOR_BRACKET_PLUS_SPACE = ") "; - const NUMBERING_SEPARATOR_BRACKET_PLUS_DOUBLE_SPACE = ") "; + public const NUMBERING_ALPHABETIC_LOWER = 'alphabetic_lower'; + public const NUMBERING_ALPHABETIC_UPPER = 'alphabetic_upper'; + public const NUMBERING_EMPTY = 'empty'; + public const NUMBERING_NUMERIC = 'numeric'; + + public const ITEMS_SEPARATOR_NO_LINE_BREAK = ""; + public const ITEMS_SEPARATOR_LINE_BREAK = "\n"; + public const ITEMS_SEPARATOR_DOUBLE_LINE_BREAK = "\n\n"; + + public const NUMBERING_SEPARATOR_NO_SPACE = ""; + public const NUMBERING_SEPARATOR_SPACE = " "; + public const NUMBERING_SEPARATOR_DOUBLE_SPACE = " "; + public const NUMBERING_SEPARATOR_DOT = "."; + public const NUMBERING_SEPARATOR_DOT_PLUS_SPACE = ". "; + public const NUMBERING_SEPARATOR_DOT_PLUS_DOUBLE_SPACE = ". "; + public const NUMBERING_SEPARATOR_BRACKET = ")"; + public const NUMBERING_SEPARATOR_BRACKET_PLUS_SPACE = ") "; + public const NUMBERING_SEPARATOR_BRACKET_PLUS_DOUBLE_SPACE = ") "; /** @var string */ protected $menu; @@ -34,10 +34,10 @@ public function __construct($menu = '') protected function numberingFor(int $index, string $numbering): string { if ($numbering === self::NUMBERING_ALPHABETIC_LOWER) { - return range('a','z')[$index]; + return range('a', 'z')[$index]; } if ($numbering === self::NUMBERING_ALPHABETIC_UPPER) { - return range('A','Z')[$index]; + return range('A', 'Z')[$index]; } if ($numbering === self::NUMBERING_NUMERIC) { return (string) $index + 1; @@ -63,8 +63,8 @@ protected function pageLimit(int $page, int $numberPerPage, array $items): int { return ( $this->isLastPage($page, $numberPerPage, $items) - ? count($items) - $this->pageStartIndex($page, $numberPerPage) - : $numberPerPage + ? count($items) - $this->pageStartIndex($page, $numberPerPage) + : $numberPerPage ); } @@ -75,7 +75,7 @@ private function listParser( string $numberingSeparator, string $itemsSeparator, string $numbering - ): void { + ): void { $startIndex = $this->pageStartIndex($page, $numberPerPage); $limit = $this->pageLimit($page, $numberPerPage, $items); for ($i = 0; $i < $limit; $i++) { diff --git a/src/Record.php b/src/Record.php index bffb352..3332a8a 100644 --- a/src/Record.php +++ b/src/Record.php @@ -52,7 +52,9 @@ protected function getDefault($default) protected function getKeys($keys) { return array_map( - function ($key) { return $this->getKey($key); }, + function ($key) { + return $this->getKey($key); + }, $keys ); } @@ -64,19 +66,19 @@ function ($key) { return $this->getKey($key); }, protected function getValues($values) { $newValues = array(); - foreach($values as $key => $value) { + foreach ($values as $key => $value) { $newValues[$this->getKey($key)] = $value; } return $newValues; } - /** - * Determine if an item exists in the cache. - * - * @param string $key - * @return bool - */ + /** + * Determine if an item exists in the cache. + * + * @param string $key + * @return bool + */ public function has($key) { return $this->cache->has($this->getKey($key)); diff --git a/src/State.php b/src/State.php index 57c8c60..1d92092 100644 --- a/src/State.php +++ b/src/State.php @@ -5,10 +5,10 @@ abstract class State { /** @var int */ - const INPUT = 'input'; + public const INPUT = 'input'; /** @var int */ - const PROMPT = 'prompt'; + public const PROMPT = 'prompt'; /** @var string */ protected $action = self::INPUT; @@ -25,11 +25,11 @@ abstract class State /** * The function to run before the rendering */ - protected abstract function beforeRendering(): void; + abstract protected function beforeRendering(): void; /** * The view to be displayed to users - * + * * @return string */ public function render(): string @@ -41,10 +41,10 @@ public function render(): string /** * The function to run after the rendering - * + * * @param string $argument */ - protected abstract function afterRendering(string $argument): void; + abstract protected function afterRendering(string $argument): void; /** * The new State full path diff --git a/src/Ussd.php b/src/Ussd.php index 15d215e..0b85a2d 100644 --- a/src/Ussd.php +++ b/src/Ussd.php @@ -25,4 +25,4 @@ public function machine() { return new Machine(); } -} \ No newline at end of file +} diff --git a/src/UssdServiceProvider.php b/src/UssdServiceProvider.php index 7e9e404..23c9756 100644 --- a/src/UssdServiceProvider.php +++ b/src/UssdServiceProvider.php @@ -15,11 +15,6 @@ class UssdServiceProvider extends ServiceProvider */ public function boot() { - // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'sparors'); - // $this->loadViewsFrom(__DIR__.'/../resources/views', 'sparors'); - // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - // $this->loadRoutesFrom(__DIR__.'/routes.php'); - // Publishing is only necessary when using the CLI. if ($this->app->runningInConsole()) { $this->bootForConsole(); @@ -50,7 +45,7 @@ public function provides() { return ['ussd']; } - + /** * Console-specific booting. * @@ -63,21 +58,6 @@ protected function bootForConsole() __DIR__.'/../config/ussd.php' => config_path('ussd.php'), ], 'ussd-config'); - // Publishing the views. - /*$this->publishes([ - __DIR__.'/../resources/views' => base_path('resources/views/vendor/sparors'), - ], 'ussd.views');*/ - - // Publishing assets. - /*$this->publishes([ - __DIR__.'/../resources/assets' => public_path('vendor/sparors'), - ], 'ussd.views');*/ - - // Publishing the translation files. - /*$this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/sparors'), - ], 'ussd.views');*/ - // Registering package commands. $this->commands([ StateCommand::class, diff --git a/tests/ActionTest.php b/tests/ActionTest.php index 7c0547c..fe974b5 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; - class ActionTest extends TestCase { public function test_it_runs_successfully() @@ -12,4 +11,4 @@ public function test_it_runs_successfully() $action = new RunAction(); $this->assertEquals(ByeState::class, $action->run()); } -} \ No newline at end of file +} diff --git a/tests/ByeState.php b/tests/ByeState.php index 010061a..3caf6e9 100644 --- a/tests/ByeState.php +++ b/tests/ByeState.php @@ -16,6 +16,5 @@ public function beforeRendering(): void public function afterRendering(string $argument): void { - } } diff --git a/tests/DecisionTest.php b/tests/DecisionTest.php index 81be085..113bf95 100644 --- a/tests/DecisionTest.php +++ b/tests/DecisionTest.php @@ -63,7 +63,7 @@ public function test_it_can_use_your_custom_conditional_logic() { $decision = new Decision(['active' => true]); $this->assertEquals('Custom', $decision - ->custom(function ($argument) { + ->custom(function ($argument) { return $argument['active']; }, 'Custom')->outcome()); } diff --git a/tests/MenuTest.php b/tests/MenuTest.php index a43bdc7..100a1d6 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -21,46 +21,51 @@ public function test_it_can_be_converted_to_string_explicitly() public function test_it_can_have_line_break() { - $menu = new Menu; + $menu = new Menu(); $this->assertEquals("\n", $menu->lineBreak()); } public function test_it_can_have_double_line_break() { - $menu = new Menu; + $menu = new Menu(); $this->assertEquals("\n\n", $menu->lineBreak(2)); } public function test_it_can_have_text_with_line_break() { - $menu = new Menu; + $menu = new Menu(); $this->assertEquals("Hello Ussd\n", $menu->line("Hello Ussd")); } public function test_it_can_have_text_with_no_line_break() { - $menu = new Menu; + $menu = new Menu(); $this->assertEquals("Hello Ussd", $menu->text("Hello Ussd")); } public function test_it_can_parse_a_list_to_string() { - $menu = new Menu; - $this->assertEquals("1.New Gen\n2.Old Gen", - $menu->listing(['New Gen', 'Old Gen'])); + $menu = new Menu(); + $this->assertEquals( + "1.New Gen\n2.Old Gen", + $menu->listing(['New Gen', 'Old Gen']) + ); } public function test_it_can_paginate_and_parse_a_list_to_string() { - $menu = new Menu; - $this->assertEquals("3.Extra", - $menu->paginateListing(['New Gen', 'Old Gen', 'Extra'], 2, 2)); + $menu = new Menu(); + $this->assertEquals( + "3.Extra", + $menu->paginateListing(['New Gen', 'Old Gen', 'Extra'], 2, 2) + ); } public function test_it_can_parse_a_list_to_string_with_alphabets_lower_for_numbering() { - $menu = new Menu; - $this->assertEquals("a.New Gen\nb.Old Gen", + $menu = new Menu(); + $this->assertEquals( + "a.New Gen\nb.Old Gen", $menu->listing( ['New Gen', 'Old Gen'], Menu::NUMBERING_SEPARATOR_DOT, @@ -72,8 +77,9 @@ public function test_it_can_parse_a_list_to_string_with_alphabets_lower_for_numb public function test_it_can_parse_a_list_to_string_with_alphabets_upper_for_numbering() { - $menu = new Menu; - $this->assertEquals("A.New Gen\nB.Old Gen", + $menu = new Menu(); + $this->assertEquals( + "A.New Gen\nB.Old Gen", $menu->listing( ['New Gen', 'Old Gen'], Menu::NUMBERING_SEPARATOR_DOT, @@ -85,8 +91,9 @@ public function test_it_can_parse_a_list_to_string_with_alphabets_upper_for_numb public function test_it_can_parse_a_list_to_string_with_empty_string_for_numbering() { - $menu = new Menu; - $this->assertEquals(".New Gen\n.Old Gen", + $menu = new Menu(); + $this->assertEquals( + ".New Gen\n.Old Gen", $menu->listing( ['New Gen', 'Old Gen'], Menu::NUMBERING_SEPARATOR_DOT, @@ -98,8 +105,10 @@ public function test_it_can_parse_a_list_to_string_with_empty_string_for_numberi public function test_method_can_be_chained() { - $menu = new Menu; - $this->assertEquals("Hello Ussd\n1.Ok\n2.Fine\nBye", - $menu->line('Hello Ussd')->listing(['Ok', 'Fine'])->lineBreak()->text('Bye')); + $menu = new Menu(); + $this->assertEquals( + "Hello Ussd\n1.Ok\n2.Fine\nBye", + $menu->line('Hello Ussd')->listing(['Ok', 'Fine'])->lineBreak()->text('Bye') + ); } } diff --git a/tests/RecordTest.php b/tests/RecordTest.php index 4b006eb..5eee5e9 100644 --- a/tests/RecordTest.php +++ b/tests/RecordTest.php @@ -70,4 +70,4 @@ public function test_it_can_delete_all_values() $this->assertNull($record->get('name')); $this->assertNull($record->get('version')); } -} \ No newline at end of file +}