Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[post] Laravel and cake php community packages #852

Merged
merged 3 commits into from
Nov 8, 2022
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
1,033 changes: 524 additions & 509 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,28 @@ That's why we believe the community package should be in the hands of people who

That's why we decided to separate typo3 and Nette from the core and let their active communities take over. They're not part of `rector/rector` anymore, but they're Rector extensions that you can install yourself if you need those:

You can find those at:

* https://github.com/sabbelasichon/typo3-rector
* https://github.com/efabrica-team/rector-nette

<br>

**How to upgrade to Typo3 community Rector package?**
### How to upgrade to Typo3 community Rector package?

Add package via composer:
Add [new package](https://github.com/sabbelasichon/typo3-rector) via composer:

```bash
composer require sabbelasichon/typo3-rector --dev
```

<br>

**How to upgrade to Nette community Rector package?**
### How to upgrade to Nette community Rector package?

Add package via composer:
Add [new package](https://github.com/efabrica-team/rector-nette) via composer:

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

<br>

And replace namespace:

```diff
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
id: 43
title: "Separating Laravel and CakePHP as Community Packages"
perex: |
Rector is built for and on the whole PHP community right from the start. But there are also somewhat "local" PHP communities around a specific framework. Each framework has specific needs that are best known to the community member.
<br><br>
That's [why we entirely moved Typo3 and Nette](/blog/separating-typo3-and-nette-as-community-packages) Rector extensions **to their communities**. They know best how to handle rules for the framework.
<br><br>
We want to encourage the community to build their own packages on top of Rector core, so we also decided to move Laravel and CakePHP to the community.

since_rector: "0.14.7"
---

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Based on a great experience with other frameworks, it&#39;s time to give <a href="https://twitter.com/hashtag/laravel?src=hash&amp;ref_src=twsrc%5Etfw">#laravel</a> <a href="https://twitter.com/rectorphp?ref_src=twsrc%5Etfw">@rectorphp</a> package to the community it belongs to 🙏<br><br>We look for person, who will take over current package <a href="https://t.co/S1rlIiRfZr">https://t.co/S1rlIiRfZr</a> and builds it further into propper &quot;Laractor&quot;😉</p>&mdash; Rector (@rectorphp) <a href="https://twitter.com/rectorphp/status/1585361016262639616?ref_src=twsrc%5Etfw">October 26, 2022</a></blockquote>

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

<br><br>

## Communities in Control of Their Standards

The significant advantage of community-maintained packages over core ones is that every community has its standards. Those standards are specific to the particular community but not useful for general Rector users. E.g., Laravel uses Blade, a PHP template syntax that can be automated, too.

We want to give these communities the freedom to implement any feature their framework needs. Having these packages in the core, where there are no Laravel and CakePHP developers, only drags those down.

As a side effect, Rector users who do not use particular community packages benefit from this too. Their Rector install load is now smaller and pulls fewer dependencies.

## Community Leaders with Strong Vision

Second, the framework communities are driven by their passionate leaders. There is no Symfony without Fabien, no Laravel without Taylor. Leaders need freedom, responsibility, and power to decide where the project should go. Of course, they discuss their opinions with others before making a move, but in the end, it is their decision to move in this or that direction.

That's why the community package should be in the hands of people who use the framework daily. A new framework version brings new features every year. The person who converts them to Rector rules is a passionate developer with a taste for innovation and a bleeding edge.

<br>

That's why we decided to separate Laravel and CakePHP from the core and let their active communities take over. They're not part of `rector/rector` anymore, but they're Rector extensions that you can install standalone.

<br>

### How to upgrade to the Laravel community Rector package?

Add [new package](https://github.com/driftingly/rector-laravel) via composer:

```bash
composer require driftingly/rector-laravel --dev
```

<br>

**Big thanks to [Anthony Clark, aka driftingly](https://github.com/driftingly)** from Tighten for making this happen promptly and with a smooth swipe 🙏

<br>

### How to upgrade to the CakePHP community Rector package?

Add [new package](https://github.com/cakephp/upgrade) via composer:

```bash
composer require cakephp/upgrade --dev
```

<br>

That's it!


<br>

We believe this brings faster iterations of the packages and focuses on a stronger Rector core to support their growth.
8 changes: 4 additions & 4 deletions packages/Blog/FileSystem/PathAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function detectDate(SmartFileInfo $fileInfo): ?DateTimeInterface

public function getSlug(SmartFileInfo $fileInfo): string
{
$date = $this->detectDate($fileInfo);
$dateTime = $this->detectDate($fileInfo);

if (! $date instanceof \DateTimeInterface) {
if (! $dateTime instanceof DateTimeInterface) {
throw new ShouldNotHappenException();
}

Expand All @@ -49,10 +49,10 @@ public function getSlug(SmartFileInfo $fileInfo): string
$match = (array) Strings::match($fileInfo->getFilename(), $dateAndNamePattern);

$dateLessBreakDateTime = DateTime::from('2021-04-01');
if ($date >= $dateLessBreakDateTime) {
if ($dateTime >= $dateLessBreakDateTime) {
return $match['name'];
}

return $date->format('Y/m/d') . '/' . $match['name'];
return $dateTime->format('Y/m/d') . '/' . $match['name'];
}
}
4 changes: 2 additions & 2 deletions packages/Blog/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
public function getPosts(): array
{
$posts = $this->posts;
return array_filter($posts, fn (Post $post): bool => ! $post->isDeprecated());
return array_filter($posts, static fn(Post $post): bool => ! $post->isDeprecated());
}

public function findBySlug(string $slug): ?Post
Expand Down Expand Up @@ -99,7 +99,7 @@ private function sortByDateTimeFromNewest(array $posts): array
{
usort(
$posts,
fn (Post $firstPost, Post $secondPost): int => $secondPost->getDateTime() <=> $firstPost->getDateTime()
static fn(Post $firstPost, Post $secondPost): int => $secondPost->getDateTime() <=> $firstPost->getDateTime()
);

return $posts;
Expand Down
2 changes: 1 addition & 1 deletion packages/Blog/Twig/RoutingTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ private function resolveCurrentRoute(Request $request): string
{
$currentRouteName = $request->get('_route');

return ltrim($currentRouteName, '/');
return ltrim((string) $currentRouteName, '/');
}
}
4 changes: 2 additions & 2 deletions packages/Blog/ValueObject/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
private readonly ?string $updatedMessage = null,
private readonly ?DateTimeInterface $deprecatedSince = null,
private readonly ?string $deprecatedMessage = null,
private readonly ?float $sinceRector = null
private readonly ?string $sinceRector = null
) {
$this->plaintextContent = strip_tags($htmlContent);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public function getUpdatedMessage(): ?string
return $this->updatedMessage;
}

public function getSinceRector(): ?float
public function getSinceRector(): ?string
{
return $this->sinceRector;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/Blog/ValueObjectFactory/PostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
) : null;
$deprecatedMessage = $configuration['deprecated_message'] ?? null;

$sinceRector = isset($configuration['since_rector']) ? (string) $configuration['since_rector'] : null;

return new Post(
$id,
$title,
Expand All @@ -103,7 +105,7 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
$updatedMessage,
$deprecatedSince,
$deprecatedMessage,
$configuration['since_rector'] ?? null
$sinceRector
);
}

Expand All @@ -116,11 +118,10 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
*/
private function decorateHeadlineWithId(string $htmlContent): string
{
return Strings::replace($htmlContent, self::HEADLINE_REGEX, function ($matches): string {
return Strings::replace($htmlContent, self::HEADLINE_REGEX, static function ($matches) : string {
$level = $matches['level'];
$headline = $matches['headline'];
$idValue = Strings::webalize($headline);

return sprintf('<h%d id="%s">%s</h%d>', $level, $idValue, $headline, $level);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/Demo/Error/ErrorMessageNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function normalize(string $errorMessage): string
return $errorMessage;
}

$type = ucfirst($match['type']);
$type = ucfirst((string) $match['type']);
$classLikeName = $match['class_like_name'];
$classCode = lcfirst($type) . ' ' . $classLikeName . ' {}';

Expand Down
3 changes: 1 addition & 2 deletions src/Twig/TitleTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ final class TitleTwigExtension extends AbstractExtension
*/
public function getFilters(): array
{
$twigFilter = new TwigFilter('clear_title', function (string $title): string {
$twigFilter = new TwigFilter('clear_title', static function (string $title) : string {
$clearTitle = strip_tags($title);

return str_replace('&nbsp;', ' ', $clearTitle);
});

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/StringsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function camelCaseToGlue(string $input, string $glue): string
$matches = Strings::matchAll($input, self::CAMEL_CASE_BY_WORD_REGEX);
$parts = [];
foreach ($matches as $match) {
$parts[] = $match[0] === strtoupper((string) $match[0]) ? strtolower($match[0]) : lcfirst($match[0]);
$parts[] = $match[0] === strtoupper((string) $match[0]) ? strtolower($match[0]) : lcfirst((string) $match[0]);
}

return implode($glue, $parts);
Expand Down