Skip to content

Commit

Permalink
Merge pull request #24 from tattersoftware/tools
Browse files Browse the repository at this point in the history
Update Toolkit
  • Loading branch information
MGatner committed Jan 4, 2022
2 parents bd86605 + e6f273c commit 02b8e72
Show file tree
Hide file tree
Showing 31 changed files with 1,228 additions and 1,225 deletions.
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
);
*/
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require-dev": {
"codeigniter4/codeigniter4": "dev-develop",
"tatter/tools": "^1.12"
"tatter/tools": "^1.15"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -56,7 +56,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
38 changes: 19 additions & 19 deletions examples/Handlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@

class Handlers extends \Tatter\Handlers\Config\Handlers
{
/**
* Classes to ignore across all handlers.
*
* @var array<string>
*/
public $ignoredClasses = [];
/**
* Classes to ignore across all handlers.
*
* @var array<string>
*/
public $ignoredClasses = [];

/**
* Paths to check during automatic discovery.
*
* @var array<string>
*/
public $autoDiscover = [];
/**
* Paths to check during automatic discovery.
*
* @var array<string>
*/
public $autoDiscover = [];

/**
* Number of seconds to cache discovered handlers.
* Null disables caching
*
* @var int|null
*/
public $cacheDuration = DAY;
/**
* Number of seconds to cache discovered handlers.
* Null disables caching
*
* @var int|null
*/
public $cacheDuration = DAY;
}
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/*
ignoreErrors:
Expand Down
33 changes: 16 additions & 17 deletions src/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@

abstract class BaseHandler implements HandlerInterface
{
use \Tatter\Handlers\Traits\HandlerTrait;
use \Tatter\Handlers\Traits\HandlerTrait;

/**
* Attributes for Tatter\Handlers.
*
* @var array
*/
protected $attributes = [];
/**
* Attributes for Tatter\Handlers.
*
* @var array
*/
protected $attributes = [];

/**
* Checks for and merges default attributes.
*/
public function __construct()
{
if (property_exists($this, 'defaults') && is_array($this->defaults))
{
$this->attributes = array_merge($this->defaults, $this->attributes);
}
}
/**
* Checks for and merges default attributes.
*/
public function __construct()
{
if (property_exists($this, 'defaults') && is_array($this->defaults)) {
$this->attributes = array_merge($this->defaults, $this->attributes);
}
}
}
72 changes: 34 additions & 38 deletions src/Commands/HandlersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,38 @@

class HandlersList extends BaseCommand
{
protected $group = 'Housekeeping';
protected $name = 'handlers:list';
protected $description = 'List all discovered handlers';
protected $usage = 'handlers:list';

public function run(array $params = [])
{
// Load the library
$handlers = new Handlers();

// Make sure auto-discovery is enabled
if (empty($handlers->getConfig()->autoDiscover))
{
CLI::write('No paths are set for automatic discovery. See the config file for Tatter\Handlers.', 'yellow');

return;
}

// Process each path
foreach ($handlers->getConfig()->autoDiscover as $path)
{
$handlers->setPath($path);
CLI::write($path, 'black', 'light_gray');

if (! $classes = $handlers->all())
{
CLI::write('No handlers detected.', 'yellow');

continue;
}

// Display each class
foreach ($classes as $class)
{
CLI::write($class);
}
}
}
protected $group = 'Housekeeping';
protected $name = 'handlers:list';
protected $description = 'List all discovered handlers';
protected $usage = 'handlers:list';

public function run(array $params = [])
{
// Load the library
$handlers = new Handlers();

// Make sure auto-discovery is enabled
if (empty($handlers->getConfig()->autoDiscover)) {
CLI::write('No paths are set for automatic discovery. See the config file for Tatter\Handlers.', 'yellow');

return;
}

// Process each path
foreach ($handlers->getConfig()->autoDiscover as $path) {
$handlers->setPath($path);
CLI::write($path, 'black', 'light_gray');

if (! $classes = $handlers->findAll()) {
CLI::write('No handlers detected.', 'yellow');

continue;
}

// Display each class
foreach ($classes as $class) {
CLI::write($class);
}
}
}
}

0 comments on commit 02b8e72

Please sign in to comment.