Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 20, 2021
0 parents commit b662ae9
Show file tree
Hide file tree
Showing 76 changed files with 3,534 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore

ecs.php export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
stubs export-ignore
tests export-ignore
35 changes: 35 additions & 0 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code Analysis

on:
pull_request: null
push:
branches:
- main

jobs:
code_analysis:
runs-on: ubuntu-latest
strategy:
matrix:
actions:
-
name: 'PHPStan'
run: composer phpstan
-
name: 'ECS'
run: composer check-cs

name: ${{ matrix.actions.name }}

steps:
- uses: actions/checkout@v2

-
uses: shivammathur/setup-php@v2
with:
php-version: 7.3
coverage: none

- uses: "ramsey/composer-install@v1"

- run: ${{ matrix.actions.run }}
29 changes: 29 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
pull_request: null
push:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']

name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2

-
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- uses: "ramsey/composer-install@v1"

- run: vendor/bin/phpunit tests
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/vendor
composer.lock

# PHPStorm meta files
.idea/

.phpunit.result.cache

# often customized locally - example on Github is just fine
rector-recipe.php

# testing
abz

# scoped & downgraded version
php-scoper.phar
box.phar
php-parallel-lint

tmp
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Rector Rules for CakePHP

## Install

```bash
composer require rector/rector-cakephp
```

@todo
36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "rector/rector-cackephp",
"license": "MIT",
"description": "Rector upgrades rules for CakePHP",
"require": {
"php": ">=7.3",
"ext-xml": "*",
"rector/rector": "dev-main"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symplify/phpstan-rules": "^9.2",
"symplify/phpstan-extensions": "^9.2",
"symplify/easy-coding-standard": "^9.2"
},
"autoload": {
"psr-4": {
"Rector\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Rector\\Tests\\": "tests"
},
"classmap": [
"stubs"
]
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi"
},
"minimum-stability": "dev",
"prefer-stable": true
}
21 changes: 21 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/../phpstan-for-rector.neon');

$services = $containerConfigurator->services();

$services->defaults()
->public()
->autowire()
->autoconfigure();

$services->load('Rector\\', __DIR__ . '/../src')
->exclude([__DIR__ . '/../src/*/{Rector,ValueObject,Contract}']);
};
90 changes: 90 additions & 0 deletions config/sets/cakephp-fluent-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

use Rector\CakePHP\Rector\MethodCall\ArrayToFluentCallRector;
use Rector\CakePHP\ValueObject\ArrayToFluentCall;
use Rector\CakePHP\ValueObject\FactoryMethod;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(ArrayToFluentCallRector::class)
->call('configure', [[
ArrayToFluentCallRector::ARRAYS_TO_FLUENT_CALLS => ValueObjectInliner::inline([
new ArrayToFluentCall('Cake\ORM\Association', [
'bindingKey' => 'setBindingKey',
'cascadeCallbacks' => 'setCascadeCallbacks',
'className' => 'setClassName',
'conditions' => 'setConditions',
'dependent' => 'setDependent',
'finder' => 'setFinder',
'foreignKey' => 'setForeignKey',
'joinType' => 'setJoinType',
'propertyName' => 'setProperty',
'sourceTable' => 'setSource',
'strategy' => 'setStrategy',
'targetTable' => 'setTarget',
# BelongsToMany and HasMany only
'saveStrategy' => 'setSaveStrategy',
'sort' => 'setSort',
# BelongsToMany only
'targetForeignKey' => 'setTargetForeignKey',
'through' => 'setThrough',
]),
new ArrayToFluentCall('Cake\ORM\Query', [
'fields' => 'select',
'conditions' => 'where',
'join' => 'join',
'order' => 'order',
'limit' => 'limit',
'offset' => 'offset',
'group' => 'group',
'having' => 'having',
'contain' => 'contain',
'page' => 'page',
]),
new ArrayToFluentCall('Cake\ORM\Association', [
'bindingKey' => 'setBindingKey',
'cascadeCallbacks' => 'setCascadeCallbacks',
'className' => 'setClassName',
'conditions' => 'setConditions',
'dependent' => 'setDependent',
'finder' => 'setFinder',
'foreignKey' => 'setForeignKey',
'joinType' => 'setJoinType',
'propertyName' => 'setProperty',
'sourceTable' => 'setSource',
'strategy' => 'setStrategy',
'targetTable' => 'setTarget',
# BelongsToMany and HasMany only
'saveStrategy' => 'setSaveStrategy',
'sort' => 'setSort',
# BelongsToMany only
'targetForeignKey' => 'setTargetForeignKey',
'through' => 'setThrough',
]),
new ArrayToFluentCall('Cake\ORM\Query', [
'fields' => 'select',
'conditions' => 'where',
'join' => 'join',
'order' => 'order',
'limit' => 'limit',
'offset' => 'offset',
'group' => 'group',
'having' => 'having',
'contain' => 'contain',
'page' => 'page',
]),
]),
ArrayToFluentCallRector::FACTORY_METHODS => ValueObjectInliner::inline([
new FactoryMethod('Cake\ORM\Table', 'belongsTo', 'Cake\ORM\Association', 2),
new FactoryMethod('Cake\ORM\Table', 'belongsToMany', 'Cake\ORM\Association', 2),
new FactoryMethod('Cake\ORM\Table', 'hasMany', 'Cake\ORM\Association', 2),
new FactoryMethod('Cake\ORM\Table', 'hasOne', 'Cake\ORM\Association', 2),
new FactoryMethod('Cake\ORM\Table', 'find', 'Cake\ORM\Query', 2),
]),
]]);
};
37 changes: 37 additions & 0 deletions config/sets/cakephp30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Rector\CakePHP\Rector\FileWithoutNamespace\ImplicitShortClassNameUseStatementRector;
use Rector\CakePHP\Rector\Namespace_\AppUsesStaticCallToUseStatementRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

# @see https://github.com/cakephp/upgrade/tree/master/src/Shell/Task
$services->set(AppUsesStaticCallToUseStatementRector::class);

$services->set(ImplicitShortClassNameUseStatementRector::class);

$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
# see https://github.com/cakephp/upgrade/blob/756410c8b7d5aff9daec3fa1fe750a3858d422ac/src/Shell/Task/RenameClassesTask.php#L37
'Cake\Network\Http\HttpSocket' => 'Cake\Network\Http\Client',
'Cake\Model\ConnectionManager' => 'Cake\Database\ConnectionManager',
'Cake\TestSuite\CakeTestCase' => 'Cake\TestSuite\TestCase',
'Cake\TestSuite\Fixture\CakeTestFixture' => 'Cake\TestSuite\Fixture\TestFixture',
'Cake\Utility\String' => 'Cake\Utility\Text',
'CakePlugin' => 'Plugin',
'CakeException' => 'Exception',
# see https://book.cakephp.org/3/en/appendices/3-0-migration-guide.html#configure
'Cake\Configure\PhpReader' => 'Cake\Core\Configure\EnginePhpConfig',
'Cake\Configure\IniReader' => 'Cake\Core\Configure\EngineIniConfig',
'Cake\Configure\ConfigReaderInterface' => 'Cake\Core\Configure\ConfigEngineInterface',
# https://book.cakephp.org/3/en/appendices/3-0-migration-guide.html#request
'CakeRequest' => 'Cake\Network\Request',
],
]]);
};
Loading

0 comments on commit b662ae9

Please sign in to comment.