Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/deduplicate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ on:
branches:
- 'develop'
paths:
- 'app/**'
- 'src/**'
- 'tests/**'
- '.github/workflows/test-phpcpd.yml'
- '.github/workflows/deduplicate.yml'
push:
branches:
- 'develop'
paths:
- 'app/**'
- 'src/**'
- 'tests/**'
- '.github/workflows/test-phpcpd.yml'
- '.github/workflows/deduplicate.yml'

jobs:
build:
Expand All @@ -30,10 +32,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: phive
extensions: intl, json, mbstring, xml
tools: phpcpd
extensions: dom, mbstring

- name: Detect code duplication
run: |
sudo phive --no-progress install --global --trust-gpg-keys 4AA394086372C20A phpcpd
phpcpd src/ tests/
run: phpcpd app/ src/ tests/
4 changes: 2 additions & 2 deletions .github/workflows/inspect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ jobs:

- name: Run architectural inspection
run: |
sudo phive --no-progress install --global --trust-gpg-keys B8F640134AB1782E,A98E898BB53EB748 qossmic/deptrac
deptrac analyze --cache-file=build/deptrac.cache
sudo phive --no-progress install --global --trust-gpg-keys B8F640134AB1782E,A98E898BB53EB748 qossmic/deptrac
deptrac analyze --cache-file=build/deptrac.cache
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phpunit
tools: composer, infection, pecl, phive, phpunit
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
coverage: xdebug
env:
Expand Down Expand Up @@ -64,13 +64,15 @@ jobs:
- if: matrix.php-versions == '8.0'
name: Mutate with Infection
run: |
composer global require infection/infection
git fetch --depth=1 origin $GITHUB_BASE_REF
infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations

- if: matrix.php-versions == '8.0'
name: Run Coveralls
run: vendor/bin/php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
continue-on-error: true
run: |
sudo phive --no-progress install --global --trust-gpg-keys E82B2FB314E9906E php-coveralls
php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/unused.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# When a PR is opened or a push is made, check code
# for unused packages with Composer Unused.
name: Unused

on:
pull_request:
branches:
- 'develop'
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/unused.yml'
push:
branches:
- 'develop'
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/unused.yml'

jobs:
build:
name: Unused Package Detection
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: composer, composer-unused
extensions: intl, json, mbstring, xml
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies (limited)
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader

- name: Install dependencies (authenticated)
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Detect unused packages
run: composer-unused -vvv --profile --ansi --no-interaction --no-progress --excludePackage=php
16 changes: 1 addition & 15 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@
->exclude('build')
->append([__FILE__]);

// Remove overrides for incremental changes
$overrides = [
'array_indentation' => false,
'braces' => false,
'indentation_type' => false,
];
$overrides = [];

$options = [
'finder' => $finder,
'cacheFile' => 'build/.php-cs-fixer.cache',
];

return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();

/* Reenable For libraries after incremental changes are applied
return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary(
'Tatter ________',
'Tatter Software',
'',
2021
);
*/
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
},
"require-dev": {
"codeigniter4/codeigniter4": "dev-develop",
"codeigniter4/codeigniter4-standard": "^1.0",
"tatter/tools": "^1.12"
"tatter/tools": "^1.15"
},
"autoload": {
"psr-4": {
Expand All @@ -43,7 +42,7 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4"
"url": "https://github.com/codeigniter4/CodeIgniter4.git"
}
],
"minimum-stability": "dev",
Expand All @@ -55,7 +54,6 @@
"@deduplicate",
"@analyze",
"@test",
"@mutate",
"@inspect",
"@style"
],
Expand Down
3 changes: 3 additions & 0 deletions depfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ ruleset:
- Entity
- Service
- Vendor Config
- Vendor Entity
- Vendor Model
Service:
- Config
- Vendor Config

# Ignore anything in the Vendor layers
Vendor Model:
- Config
- Service
- Vendor Config
- Vendor Controller
Expand All @@ -130,6 +132,7 @@ ruleset:
- Vendor Model
- Vendor View
Vendor Config:
- Config
- Service
- Vendor Config
- Vendor Controller
Expand Down
18 changes: 9 additions & 9 deletions examples/Permits.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

class Permits extends \Tatter\Permits\Config\Permits
{
// key in $_SESSION that contains the integer ID of a logged in user
public $sessionUserId = 'logged_in';
// key in $_SESSION that contains the integer ID of a logged in user
public $sessionUserId = 'logged_in';

// whether to implement groups access across the library
// set to 'false' if you don't have a groups table implemented
public $useGroups = true;
// whether to implement groups access across the library
// set to 'false' if you don't have a groups table implemented
public $useGroups = true;

// number of seconds to cache a permission
public $cacheDuration = 60;
// number of seconds to cache a permission
public $cacheDuration = 60;

// whether to continue instead of throwing exceptions
public $silent = true;
// whether to continue instead of throwing exceptions
public $silent = true;
}
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
- tests
bootstrapFiles:
- vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php
excludes_analyse:
excludePaths:
- src/Config/Routes.php
- src/Views/*
- src/Models/UserModel.php
Expand Down
102 changes: 47 additions & 55 deletions src/Commands/PermitsAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,51 @@

class PermitsAdd extends BaseCommand
{
protected $group = 'Auth';
protected $name = 'permits:add';
protected $description = 'Adds a permit to the database.';

protected $usage = 'permits:add [permission] [target] [id]';
protected $arguments = [
'permission' => "The name of the permission to grant (e.g. 'listJobs')",
'target' => "The type of recipient ('groups' or 'users')",
'id' => "The ID of the recipient (e.g. '42')",
];

public function run(array $params = [])
{
$permits = new PermitModel();

// Consume or prompt for the permission name
$permission = array_shift($params);
if (empty($permission))
{
$permission = CLI::prompt('Permission to grant', null, 'required');
}

// Consume or prompt for the target table
$target = array_shift($params);
if (empty($target))
{
$target = CLI::prompt('Target', ['groups', 'users']);
}

// Consume or prompt for the target ID
$id = array_shift($params);
if (empty($id))
{
$id = CLI::prompt(ucfirst(substr($target, 0, -1)) . ' ID', null, 'is_natural_no_zero');
}

if ($target === 'groups')
{
$row['group_id'] = $id;
}
else {
$row['user_id'] = $id;
}
$row['name'] = $permission;

try {
$permits->save($row);
}
catch (\Exception $e)
{
$this->showError($e);
}

$this->call('permits:list');
}
protected $group = 'Auth';
protected $name = 'permits:add';
protected $description = 'Adds a permit to the database.';
protected $usage = 'permits:add [permission] [target] [id]';
protected $arguments = [
'permission' => "The name of the permission to grant (e.g. 'listJobs')",
'target' => "The type of recipient ('groups' or 'users')",
'id' => "The ID of the recipient (e.g. '42')",
];

public function run(array $params = [])
{
$permits = new PermitModel();

// Consume or prompt for the permission name
$permission = array_shift($params);
if (empty($permission)) {
$permission = CLI::prompt('Permission to grant', null, 'required');
}

// Consume or prompt for the target table
$target = array_shift($params);
if (empty($target)) {
$target = CLI::prompt('Target', ['groups', 'users']);
}

// Consume or prompt for the target ID
$id = array_shift($params);
if (empty($id)) {
$id = CLI::prompt(ucfirst(substr($target, 0, -1)) . ' ID', null, 'is_natural_no_zero');
}

if ($target === 'groups') {
$row['group_id'] = $id;
} else {
$row['user_id'] = $id;
}
$row['name'] = $permission;

try {
$permits->save($row);
} catch (\Exception $e) {
$this->showError($e);
}

$this->call('permits:list');
}
}
Loading