Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 18, 2021
0 parents commit 35c81c3
Show file tree
Hide file tree
Showing 373 changed files with 21,206 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 Nette

## Install

```bash
composer require rector/rector-nette
```

@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-nette",
"license": "MIT",
"description": "Rector upgrades rules for Nette Framework",
"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
}
17 changes: 17 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

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

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

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

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

$parameters->set(Option::PATHS, [
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/config',
__DIR__ . '/ecs.php',
]);

$parameters->set(Option::SETS, [SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]);
$parameters->set(Option::SKIP, [
'*/Source/*', '*/Fixture/*',

// breaks annotated code - removed on symplify dev-main
\PhpCsFixer\Fixer\ReturnNotation\ReturnAssignmentFixer::class,
]);
$parameters->set(Option::LINE_ENDING, "\n");
};
58 changes: 58 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
includes:
- vendor/symplify/phpstan-extensions/config/config.neon
- vendor/symplify/phpstan-rules/config/symplify-rules.neon

parameters:
level: max

paths:
- config
- src
- tests

scanDirectories:
- stubs

excludePaths:
- */Source/*
- *Source/*

# ignoreErrors:
# -
# message: '#Do not inherit from abstract class, better use composition#'
# path: "*Rector.php"
#
# - '#Constant string value need to only have small letters, _, \-, \. and numbers#'
#
# # symfony native values
# -
# message: '#Parameter "(.*?)" cannot be nullable#'
# path: src/Symfony/ValueObject/ServiceDefinition.php
#
# -
# message: '#Use decoupled factory service to create "PHPStan\\Type\\ObjectType" object#'
# path: src/Symfony/ValueObject/ServiceMap/ServiceMap.php
#
# -
# message: '#Parameter "return" cannot be nullable#'
# path: src/Symfony/NodeFactory/ThisRenderFactory.php
#
# # fixed in dev php-parser
# - '#Method Rector\\Symfony\\NodeFactory\\RouteNameClassFactory\:\:create\(\) should return PhpParser\\Node\\Stmt\\Namespace_ but returns PhpParser\\Node#'
#
# # should be fixed on master
# -
# message: '#Do not use chained method calls\. Put each on separated lines#'
# paths:
# - src/Symfony/ConstantNameAndValueMatcher.php
#
# -
# message: '#Parameter "priority" cannot be nullable#'
# paths:
# - src/Symfony/NodeFactory/GetSubscribedEventsClassMethodFactory.php
#
# # good place for value object
# -
# message: '#Use another value object over array with string\-keys and objects, array<string, ValueObject\>#'
# paths:
# - src/Symfony3/Rector/MethodCall/FormTypeInstanceToClassConstRector.php
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="main">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 22 additions & 0 deletions src/Nette/Contract/PregToNetteUtilsStringInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Rector\Nette\Contract;

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;

interface PregToNetteUtilsStringInterface
{
public function refactorIdentical(Identical $identical): ?Bool_;

/**
* @return FuncCall|StaticCall|Assign|null
*/
public function refactorFuncCall(FuncCall $funcCall): ?Expr;
}
20 changes: 20 additions & 0 deletions src/Nette/Contract/ValueObject/ParameterArrayInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Rector\Nette\Contract\ValueObject;

use PhpParser\Node\Expr;

interface ParameterArrayInterface
{
/**
* @return array<string, Expr>
*/
public function getTemplateVariables(): array;

/**
* @return string[]
*/
public function getConditionalVariableNames(): array;
}
36 changes: 36 additions & 0 deletions src/Nette/NodeAnalyzer/ConditionalTemplateAssignReplacer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Rector\Nette\NodeAnalyzer;

use PhpParser\Node\Expr\Variable;
use Rector\Nette\ValueObject\TemplateParametersAssigns;

/**
* Replaces:
*
* if (...) {
* $this->template->key = 'some';
* } else {
* $this->template->key = 'another';
* }
*
* ↓
*
* if (...) {
* $key = 'some';
* } else {
* $key = 'another';
* }
*/
final class ConditionalTemplateAssignReplacer
{
public function processClassMethod(TemplateParametersAssigns $templateParametersAssigns): void
{
foreach ($templateParametersAssigns->getConditionalTemplateParameterAssign() as $conditionalTemplateParameterAssign) {
$assign = $conditionalTemplateParameterAssign->getAssign();
$assign->var = new Variable($conditionalTemplateParameterAssign->getParameterName());
}
}
}
Loading

0 comments on commit 35c81c3

Please sign in to comment.