Skip to content

Commit

Permalink
Fix Coding Style (#17)
Browse files Browse the repository at this point in the history
* Format Code

* Update changelog and readme
  • Loading branch information
cybersai authored Oct 15, 2021
1 parent a2eed85 commit 03c8cfc
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
composer.lock
.phpunit.result.cache
testbench/
/coverage
/coverage
.DS_Store
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/ussd.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| State Class Namespace
Expand Down Expand Up @@ -62,4 +62,4 @@
*/

'cache_default' => env('USSD_DEFAULT_VALUE', null),
];
];
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class Action
/** @var Record */
protected $record;

public abstract function run(): string;
abstract public function run(): string;

/**
* @param Record $record
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -46,4 +46,4 @@ protected function ensureDirectoryExists($namespace, $relativePath)
File::makeDirectory(dirname($path), 0777, $recursive = true, $force = true);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Facades/Ussd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/HasManipulators.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -106,7 +106,7 @@ public function setInitialState($state)
} else {
$this->initialState = null;
}

return $this;
}

Expand Down
19 changes: 9 additions & 10 deletions src/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Machine

/** @var Record */
protected $record;

/** @var string|null */
protected $sessionId;

Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct()
public function run()
{
$this->ensureSessionIdIsSet($this->sessionId);

$this->record = new Record(
Cache::store($this->store),
$this->sessionId
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
);
}

Expand All @@ -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++) {
Expand Down
18 changes: 10 additions & 8 deletions src/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand All @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions src/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Ussd.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public function machine()
{
return new Machine();
}
}
}
22 changes: 1 addition & 21 deletions src/UssdServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -50,7 +45,7 @@ public function provides()
{
return ['ussd'];
}

/**
* Console-specific booting.
*
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 03c8cfc

Please sign in to comment.