Skip to content

Commit

Permalink
Adds php-cs-fixer. Formats code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mabasic committed Mar 24, 2021
1 parent a3fd144 commit 2e76903
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
composer.lock
.phpunit.result.cache
.phpunit.result.cache
.php_cs.cache
19 changes: 19 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(['.github','vendor'])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR1' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
])
->setFinder($finder);
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ The same as `Ekko::isActive`. This method encloses the input with wildcard `*`.
The same as `Ekko::isActiveMatch`, but accepts only the array of strings.
**Backward compatibility.** Use `Ekko::isActive` and pass it the same array.

## Development

```bash
# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Run Psalm
vendor/bin/psalm

# Format code (php-cs-fixer)
vendor/bin/php-cs-fixer
```

## Credits

Many thanks to:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"mockery/mockery": "^1.4",
"illuminate/support": "^8.0",
"illuminate/routing": "^8.0",
"vimeo/psalm": "^4.6"
"vimeo/psalm": "^4.6",
"friendsofphp/php-cs-fixer": "^2.18"
},
"extra": {
"laravel": {
Expand Down
16 changes: 8 additions & 8 deletions src/Ekko.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Laravelista\Ekko;

use Laravelista\Ekko\Url\UrlProviderInterface;
use Laravelista\Ekko\Url\GenericUrlProvider;
use Laravelista\Ekko\Url\UrlProviderInterface;

/**
* This is the main (core) class of Ekko.
Expand All @@ -13,11 +13,6 @@
*/
class Ekko
{
public function __construct()
{
$this->url = new GenericUrlProvider;
}

/**
* This value gets returned if the
* given output equals null.
Expand All @@ -33,14 +28,19 @@ public function __construct()
*/
protected UrlProviderInterface $url;

public function __construct()
{
$this->url = new GenericUrlProvider();
}

/**
* This static method uses `require_once` to
* include global helper functions. By default
* global functions are not enabled.
*
* @return void
*/
static public function enableGlobalHelpers()
public static function enableGlobalHelpers()
{
require_once(__DIR__.'/Helpers.php');
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public function getCurrentUrl(): string
*/
protected function inArray(array $input, string $methodName): bool
{
foreach($input as $url) {
foreach ($input as $url) {
if ($this->$methodName($url, true)) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Frameworks/Laravel/Ekko.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Ekko extends \Laravelista\Ekko\Ekko
*/
public function __construct(protected Router $router)
{
parent::__construct();
parent::__construct();
}

/**
Expand All @@ -23,7 +23,7 @@ public function __construct(protected Router $router)
*
* @return void
*/
static public function enableGlobalHelpers()
public static function enableGlobalHelpers()
{
require_once(__DIR__.'/Helpers.php');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Frameworks/Laravel/Helpers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Illuminate\Support\Facades\App;
use \Laravelista\Ekko\Frameworks\Laravel\Ekko;
use Laravelista\Ekko\Frameworks\Laravel\Ekko;

/**
* Route
Expand Down Expand Up @@ -62,7 +62,7 @@ function are_active_routes(array|string $input, mixed $output = null): mixed
if (!function_exists('is_active')) {
/**
* Backward compatibility with v2.
*
*
* @param array|string $input URL or array of URLs.
* @param null|mixed $output User given output.
* @return mixed|null Either user given output or the default output value or null.
Expand Down Expand Up @@ -171,4 +171,4 @@ function are_active_matches(array|string $input, mixed $output = null): mixed
{
return App::resolve(Ekko::class)->isActive($input, $output);
}
}
}
20 changes: 4 additions & 16 deletions src/Frameworks/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
namespace Laravelista\Ekko\Frameworks\Laravel;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Facades\Config;
use Laravelista\Ekko\Url\LaravelUrlProvider;
// use Illuminate\Contracts\Support\DeferrableProvider;

class ServiceProvider extends \Illuminate\Support\ServiceProvider /* implements DeferrableProvider */
class ServiceProvider extends \Illuminate\Support\ServiceProvider implements DeferrableProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* Laravel 5.8
* The defer boolean property on the service provider which is/was used to
* indicate if a provider is deferred has been deprecated in Laravel 5.8.
* In order to mark the service provider as deferred it should implement
* the Illuminate\Contracts\Support\DeferrableProvider contract.
*
* @var bool
*/
protected $defer = true;

/**
* Register services.
*
Expand All @@ -30,7 +17,8 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider /* implements
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config.php', 'ekko'
__DIR__.'/config.php',
'ekko'
);

$this->app->singleton(Ekko::class, function (Application $app) {
Expand Down
2 changes: 1 addition & 1 deletion src/Frameworks/Laravel/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* is defined when user called.
*/
'default_output' => 'active',
];
];
2 changes: 1 addition & 1 deletion src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
*/
function is_active(array|string $input, $output = null)
{
return (new Ekko)->isActive($input, $output);
return (new Ekko())->isActive($input, $output);
}
}
2 changes: 1 addition & 1 deletion src/Url/GenericUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public function current(): string
// without query parameters
// return strtok($_SERVER['REQUEST_URI'], '?');
}
}
}
2 changes: 1 addition & 1 deletion src/Url/LaravelUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public function current(): string
{
return $this->request->getRequestUri();
}
}
}
6 changes: 3 additions & 3 deletions tests/EkkoTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

use PHPUnit\Framework\TestCase;
use Laravelista\Ekko\Ekko;
use Laravelista\Ekko\Url\GenericUrlProvider;
use PHPUnit\Framework\TestCase;

class EkkoTest extends TestCase
{
protected $ekko;

protected function setUp(): void
{
$this->ekko = new Ekko;
$this->ekko = new Ekko();
}

public function isActiveDataProvider()
Expand Down Expand Up @@ -115,4 +115,4 @@ public function urlProvider()
{
$this->assertInstanceOf(GenericUrlProvider::class, $this->ekko->getUrlProvider());
}
}
}
4 changes: 2 additions & 2 deletions tests/LaravelTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use \Mockery as m;
use Laravelista\Ekko\Frameworks\Laravel\Ekko;
use Laravelista\Ekko\Url\LaravelUrlProvider;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Laravelista\Ekko\Frameworks\Laravel\Ekko;

class LaravelTest extends TestCase
{
Expand Down

0 comments on commit 2e76903

Please sign in to comment.