Skip to content

Commit

Permalink
Merge pull request #2 from ARCANEDEV/update-github_actions
Browse files Browse the repository at this point in the history
Using GitHub Actions for testing
  • Loading branch information
arcanedev-maroc authored Feb 1, 2020
2 parents 242c762 + ecf35ae commit 0da5220
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 74 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
CONTRIBUTING.md export-ignore
46 changes: 46 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: run-tests

on: [push]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
laravel: [6.*]
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
- name: Scrutinizer CI
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 2
runs: 6
php_code_sniffer:
enabled: true
config:
Expand Down
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Laravel Policies [![Packagist License][badge_license]](LICENSE.md) [![For Laravel][badge_laravel]][link-github-repo]

[![Travis Status][badge_build]][link-travis]
[![Github Workflow Status][badge_build]][link-github-status]
[![Coverage Status][badge_coverage]][link-scrutinizer]
[![Scrutinizer Code Quality][badge_quality]][link-scrutinizer]
[![SensioLabs Insight][badge_insight]][link-insight]
Expand All @@ -21,7 +21,7 @@ This package allows to create & manage policies/abilities in a modular way.
* Well tested with maximum code quality.
* Laravel `6.x` is supported.
* Made with :heart: & :coffee:.

## Table of contents

1. [Installation and Setup](_docs/1-Installation-and-Setup.md)
Expand All @@ -47,7 +47,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.

[badge_laravel]: https://img.shields.io/badge/Laravel-6.x-orange.svg?style=flat-square
[badge_license]: https://img.shields.io/packagist/l/arcanedev/laravel-policies.svg?style=flat-square
[badge_build]: https://img.shields.io/travis/ARCANEDEV/LaravelPolicies.svg?style=flat-square
[badge_build]: https://img.shields.io/github/workflow/status/ARCANEDEV/LaravelPolicies/run-tests?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LaravelPolicies.svg?style=flat-square
[badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/LaravelPolicies.svg?style=flat-square
[badge_insight]: https://img.shields.io/sensiolabs/i/ee623172-802f-4775-b48b-122df1571b1b.svg?style=flat-square
Expand All @@ -58,9 +58,9 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.

[link-author]: https://github.com/arcanedev-maroc
[link-github-repo]: https://github.com/ARCANEDEV/LaravelPolicies
[link-github-status]: https://github.com/ARCANEDEV/LaravelPolicies/actions
[link-github-issues]: https://github.com/ARCANEDEV/LaravelPolicies/issues
[link-contributors]: https://github.com/ARCANEDEV/LaravelPolicies/graphs/contributors
[link-packagist]: https://packagist.org/packages/arcanedev/laravel-policies
[link-travis]: https://travis-ci.org/ARCANEDEV/LaravelPolicies
[link-scrutinizer]: https://scrutinizer-ci.com/g/ARCANEDEV/LaravelPolicies/?branch=master
[link-insight]: https://insight.sensiolabs.com/projects/ee623172-802f-4775-b48b-122df1571b1b
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"php": ">=7.2.0",
"ext-json": "*",
"arcanedev/support": "~5.0"
"arcanedev/support": "~5.1"
},
"require-dev": {
"orchestra/testbench": "~4.0",
Expand Down
9 changes: 4 additions & 5 deletions src/Ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

namespace Arcanedev\LaravelPolicies;

use Illuminate\Contracts\Support\{Arrayable, Jsonable};
use Arcanedev\LaravelPolicies\Contracts\Ability as AbilityContract;
use Closure;
use Illuminate\Support\Arr;
use JsonSerializable;

/**
* Class Ability
*
* @package Arcanedev\LaravelPolicies
* @author ARCANEDEV <[email protected]>
*/
class Ability implements Arrayable, JsonSerializable, Jsonable
class Ability implements AbilityContract
{
/* -----------------------------------------------------------------
| Properties
Expand Down Expand Up @@ -93,7 +92,7 @@ public function setKey(string $key): self
/**
* Get the ability's method.
*
* @return string|Closure
* @return \Closure|string
*/
public function method()
{
Expand All @@ -115,7 +114,7 @@ public function callback(Closure $callback): self
/**
* Set the ability's method.
*
* @param string|\Closure $method
* @param \Closure|string $method
*
* @return self
*/
Expand Down
113 changes: 113 additions & 0 deletions src/Contracts/Ability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

declare(strict_types=1);

namespace Arcanedev\LaravelPolicies\Contracts;

use Illuminate\Contracts\Support\{Arrayable, Jsonable};
use Closure;
use JsonSerializable;

/**
* Interface Ability
*
* @package Arcanedev\LaravelPolicies\Contracts
* @author ARCANEDEV <[email protected]>
*/
interface Ability extends Arrayable, JsonSerializable, Jsonable
{
/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/

/**
* Get the ability's key.
*
* @return string
*/
public function key(): string;

/**
* Set the ability's key.
*
* @param string $key
*
* @return $this
*/
public function setKey(string $key);

/**
* Get the ability's method.
*
* @return \Closure|string
*/
public function method();

/**
* Set the callback as method.
*
* @param \Closure $callback
*
* @return $this
*/
public function callback(Closure $callback);

/**
* Set the ability's method.
*
* @param \Closure|string $method
*
* @return $this
*/
public function setMethod($method);

/**
* Get the ability's meta.
*
* @return array
*/
public function metas(): array;

/**
* Set the ability's meta.
*
* @param array $metas
* @param bool $keepMetas
*
* @return $this
*/
public function setMetas(array $metas, bool $keepMetas = true);

/**
* Get a meta.
*
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
public function meta(string $key, $default = null);

/**
* Set a meta.
*
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function setMeta(string $key, $value);

/* -----------------------------------------------------------------
| Check Methods
| -----------------------------------------------------------------
*/

/**
* Check if the ability is a callback method.
*
* @return bool
*/
public function isClosure(): bool;
}
2 changes: 1 addition & 1 deletion src/PoliciesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Arcanedev\LaravelPolicies;

use Arcanedev\Support\PackageServiceProvider;
use Arcanedev\Support\Providers\PackageServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Arcanedev\LaravelPolicies;

use Arcanedev\LaravelPolicies\Contracts\Ability as AbilityContract;
use Arcanedev\LaravelPolicies\Contracts\Policy as PolicyContract;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -94,9 +95,9 @@ public static function ability($keys)
* @param string $key
* @param string|null $method
*
* @return \Arcanedev\LaravelPolicies\Ability
* @return \Arcanedev\LaravelPolicies\Contracts\Ability
*/
protected function makeAbility(string $key, $method = null): Ability
protected function makeAbility(string $key, $method = null): AbilityContract
{
return Ability::make(
static::prefixedKey($key),
Expand Down
13 changes: 6 additions & 7 deletions src/PolicyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Arcanedev\LaravelPolicies;

use Arcanedev\LaravelPolicies\Contracts\{
Policy as PolicyContract,
PolicyManager as PolicyManagerContract
};
use Arcanedev\LaravelPolicies\Contracts\Ability as AbilityContract;
use Arcanedev\LaravelPolicies\Contracts\Policy as PolicyContract;
use Arcanedev\LaravelPolicies\Contracts\PolicyManager as PolicyManagerContract;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Auth\Access\Gate;

/**
* Class PolicyManager
Expand Down Expand Up @@ -147,11 +146,11 @@ public function register(PolicyContract $policy): PolicyManagerContract
/**
* Register the ability object.
*
* @param \Arcanedev\LaravelPolicies\Ability $ability
* @param \Arcanedev\LaravelPolicies\Contracts\Ability $ability
*
* @return $this
*/
protected function registerAbility(Ability $ability)
protected function registerAbility(AbilityContract $ability)
{
$this->abilities->put($ability->key(), $ability);
$this->gate()->define($ability->key(), $ability->method());
Expand Down
Loading

0 comments on commit 0da5220

Please sign in to comment.