Skip to content

Commit

Permalink
Add Stan and Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Torann committed Sep 21, 2020
1 parent 47fc100 commit 396f4b5
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 104 deletions.
31 changes: 14 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
allow_failures:
- php: 7.0

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
language: php

php:
- 7.2
- 7.3
- 7.4

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script:
- ./vendor/bin/phpcs --standard=phpcs.xml src
- ./vendor/bin/phpstan --level=0 --no-progress analyse src
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
"require": {
"php": "^7.2",
"illuminate/support": "^6.0|^7.0|^8.0",
"illuminate/console": "^6.0|^7.0|^8.0",
"illuminate/cache": "^6.0|^7.0|^8.0"
},
"suggest": {
"illuminate/database": "Allows for storing of currencies in the database"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"mockery/mockery": "^1.3",
"phpstan/phpstan": "^0.12.14",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"files": [
"src/helpers.php"
Expand Down
26 changes: 26 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset name="PSR2-package">
<description>The PSR2 standard</description>

<!-- use preg_match https://github.com/squizlabs/PHP_CodeSniffer/issues/742#issuecomment-215250517 -->
<exclude-pattern>/resources/</exclude-pattern>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/_[a-zA-Z0-9\._]+\.php</exclude-pattern>
<exclude-pattern>/\.[a-zA-Z0-9\._]+\.php</exclude-pattern>
<exclude-pattern>\.git</exclude-pattern>

<!-- Include the whole PSR2 standard -->
<rule ref="PSR2">
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
<exclude name="PSR2.Files.EndFileNewline"/>
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
</rule>

<!-- Lines can be longer -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="9999"/>
</properties>
</rule>
</ruleset>
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
excludes_analyse:
- vendor
- resources
ignoreErrors:
- '#Function app not found#'
- '#Function config_path not found#'
- '#Function base_path not found#'
- '#Function config not found#'
- '#Parameter \$request of method#'
6 changes: 4 additions & 2 deletions src/Console/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function handle()
protected function add($currency)
{
if (($data = $this->getCurrency($currency)) === null) {
return $this->error("Currency \"{$currency}\" not found");
$this->error("Currency \"{$currency}\" not found");
return;
}

$this->output->write("Adding {$currency} currency...");
Expand All @@ -106,7 +107,8 @@ protected function add($currency)
protected function update($currency)
{
if (($data = $this->getCurrency($currency)) === null) {
return $this->error("Currency \"{$currency}\" not found");
$this->error("Currency \"{$currency}\" not found");
return;
}

$this->output->write("Updating {$currency} currency...");
Expand Down
170 changes: 85 additions & 85 deletions src/CurrencyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
<?php

namespace Torann\Currency;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

class CurrencyServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerCurrency();

if ($this->app->runningInConsole()) {
$this->registerResources();
$this->registerCurrencyCommands();
}
}

/**
* Register currency provider.
*
* @return void
*/
public function registerCurrency()
{
$this->app->singleton('currency', function ($app) {
return new Currency(
$app->config->get('currency', []),
$app['cache']
);
});
}

/**
* Register currency resources.
*
* @return void
*/
public function registerResources()
{
if ($this->isLumen() === false) {
$this->publishes([
__DIR__ . '/../config/currency.php' => config_path('currency.php'),
], 'config');

$this->mergeConfigFrom(
__DIR__ . '/../config/currency.php', 'currency'
);
}

$this->publishes([
__DIR__ . '/../database/migrations' => base_path('/database/migrations'),
], 'migrations');
}

/**
* Register currency commands.
*
* @return void
*/
public function registerCurrencyCommands()
{
$this->commands([
Console\Cleanup::class,
Console\Manage::class,
Console\Update::class,
]);
}

/**
* Check if package is running under Lumen app
*
* @return bool
*/
protected function isLumen()
{
return Str::contains($this->app->version(), 'Lumen') === true;
}
}
<?php

namespace Torann\Currency;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

class CurrencyServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerCurrency();

if ($this->app->runningInConsole()) {
$this->registerResources();
$this->registerCurrencyCommands();
}
}

/**
* Register currency provider.
*
* @return void
*/
public function registerCurrency()
{
$this->app->singleton('currency', function ($app) {
return new Currency(
$app->config->get('currency', []),
$app['cache']
);
});
}

/**
* Register currency resources.
*
* @return void
*/
public function registerResources()
{
if ($this->isLumen() === false) {
$this->publishes([
__DIR__ . '/../config/currency.php' => config_path('currency.php'),
], 'config');

$this->mergeConfigFrom(
__DIR__ . '/../config/currency.php', 'currency'
);
}

$this->publishes([
__DIR__ . '/../database/migrations' => base_path('/database/migrations'),
], 'migrations');
}

/**
* Register currency commands.
*
* @return void
*/
public function registerCurrencyCommands()
{
$this->commands([
Console\Cleanup::class,
Console\Manage::class,
Console\Update::class,
]);
}

/**
* Check if package is running under Lumen app
*
* @return bool
*/
protected function isLumen()
{
return Str::contains($this->app->version(), 'Lumen') === true;
}
}

0 comments on commit 396f4b5

Please sign in to comment.