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
8 changes: 4 additions & 4 deletions .github/workflows/test_with_doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Test_With_Doctrine
name: Test With Doctrine

on:
pull_request:
pull_request: null
push:
branches:
- master
Expand All @@ -15,6 +15,7 @@ jobs:
with:
php-version: 7.3
coverage: none

- name: Clone doctrine/orm and install safe dependencies
run: |
# cannot install dev deps (--no-dev), because doctrine/orm might inherit from them in different version
Expand All @@ -30,5 +31,4 @@ jobs:
# do not intall doctrine/orm phpstan, it conflicts with Retor's one
composer install -d orm --no-dev

- run: |
bin/rector process orm/lib --set dead-code --autoload-file orm/vendor/autoload.php
- run: bin/rector process orm/lib --set dead-code --autoload-file orm/vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# from CakePHP 2.4.6 to Symfony 5.1 (May 2020) and Twig 3
# from CakePHP 2.4.6 (April 2014) to Symfony 5.1 (May 2020) and Twig 3
services:
# https://github.com/cakephp/cakephp/blob/2.4.6/lib/Cake/Controller/Controller.php
Rector\CakePHPToSymfony\Rector\Class_\CakePHPControllerToSymfonyControllerRector: null
Expand All @@ -12,4 +12,7 @@ services:
Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateLinkToTwigRector: null
Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateTranslateToTwigRector: null
Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateHToTwigRector: null

# Model to Doctrine
Rector\CakePHPToSymfony\Rector\Class_\CakePHPModelToDoctrineEntityRector: null
Rector\CakePHPToSymfony\Rector\Class_\CakePHPModelToDoctrineRepositoryRector: null
59 changes: 58 additions & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 443 Rectors Overview
# All 444 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand Down Expand Up @@ -454,6 +454,63 @@ Migrate CakePHP Model active record to Doctrine\ORM Entity and EntityRepository

<br>

### `CakePHPModelToDoctrineRepositoryRector`

- class: `Rector\CakePHPToSymfony\Rector\Class_\CakePHPModelToDoctrineRepositoryRector`

Migrate CakePHP Model active record to Doctrine\ORM\Repository with repository/DQL method calls

```diff
-class Activity extends \AppModel
+use Doctrine\ORM\EntityManagerInterface;
+
+class Activity
{
+}
+
+class ActivityRepository
+{
+ /**
+ * @var EntityManagerInterface
+ */
+ private $repository;
+
+ public function __construct(EntityManagerInterface $entityManager)
+ {
+ $this->repository = $entityManager->getRepository(Activity::class);
+ }
+
public function getAll()
{
- $result = $this->find('all');
+ $result = $this->repository->findAll();

return $result;
}

public function getOne()
{
- $result = $this->find('first', [
- 'conditions' => [
- 'DocumentVersionsSave.revision_number' => $versionId,
- 'DocumentVersionsSave.document_id' => $documentId,
- ],
- 'order' => [
- 'created DESC',
- ],
- ]);
+ $result = $this->findOneBy([
+ 'revision_number' => $versionId,
+ 'document_id' => $documentId,
+ ], 'created DESC');

return $result;
}
}
```

<br>

### `CakePHPTemplateHToTwigRector`

- class: `Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateHToTwigRector`
Expand Down
1 change: 1 addition & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ parameters:
Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff:
# respects inherited pattern for better comparing
- 'src/PhpParser/Printer/BetterStandardPrinter.php'
- 'src/Rector/AbstractRector/BetterStandardPrinterTrait.php'

PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff.FoundInWhileCondition: null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\ObjectType;
use Rector\CakePHPToSymfony\Rector\AbstractCakePHPRector;
use Rector\CodingStyle\Naming\ClassNaming;
use Rector\Exception\ShouldNotHappenException;
use Rector\PhpParser\Node\Manipulator\ClassManipulator;
use Rector\RectorDefinition\CodeSample;
Expand All @@ -27,20 +26,14 @@ final class CakePHPControllerComponentToSymfonyRector extends AbstractCakePHPRec
*/
private $classManipulator;

/**
* @var ClassNaming
*/
private $classNaming;

/**
* @var string[]
*/
private $componentsClasses = [];

public function __construct(ClassManipulator $classManipulator, ClassNaming $classNaming)
public function __construct(ClassManipulator $classManipulator)
{
$this->classManipulator = $classManipulator;
$this->classNaming = $classNaming;
}

public function getDefinition(): RectorDefinition
Expand Down Expand Up @@ -131,7 +124,7 @@ public function refactor(Node $node): ?Node
$oldProperyNameToNewPropertyName = [];

foreach ($componentClasses as $componentName => $componentClass) {
$componentClassShortName = $this->classNaming->getShortName($componentClass);
$componentClassShortName = $this->getShortName($componentClass);
$propertyShortName = lcfirst($componentClassShortName);
$this->addPropertyToClass($node, new ObjectType($componentClass), $propertyShortName);

Expand Down Expand Up @@ -179,7 +172,7 @@ private function matchComponentClass(array $componentNames): array

foreach ($componentNames as $componentName) {
foreach ($componentsClasses as $componentClass) {
$shortComponentClass = $this->classNaming->getShortName($componentClass);
$shortComponentClass = $this->getShortName($componentClass);
if (! Strings::startsWith($shortComponentClass, $componentName)) {
continue;
}
Expand Down
Loading