Skip to content

Commit 65aa09f

Browse files
authored
[post] laral cake php comunity (#852)
1 parent d1c9f76 commit 65aa09f

11 files changed

+615
-534
lines changed

composer.lock

+524-509
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/blog/posts/2022/2022-08-05-separating-typo3-and-nette-as-community-packages.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,28 @@ That's why we believe the community package should be in the hands of people who
3333

3434
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:
3535

36-
You can find those at:
37-
38-
* https://github.com/sabbelasichon/typo3-rector
39-
* https://github.com/efabrica-team/rector-nette
40-
4136
<br>
4237

43-
**How to upgrade to Typo3 community Rector package?**
38+
### How to upgrade to Typo3 community Rector package?
4439

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

4742
```bash
4843
composer require sabbelasichon/typo3-rector --dev
4944
```
5045

5146
<br>
5247

53-
**How to upgrade to Nette community Rector package?**
48+
### How to upgrade to Nette community Rector package?
5449

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

5752
```bash
5853
composer require efabrica/rector-nette --dev
5954
```
6055

56+
<br>
57+
6158
And replace namespace:
6259

6360
```diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
id: 43
3+
title: "Separating Laravel and CakePHP as Community Packages"
4+
perex: |
5+
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.
6+
<br><br>
7+
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.
8+
<br><br>
9+
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.
10+
11+
since_rector: "0.14.7"
12+
---
13+
14+
<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>
15+
16+
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
17+
18+
<br><br>
19+
20+
## Communities in Control of Their Standards
21+
22+
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.
23+
24+
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.
25+
26+
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.
27+
28+
## Community Leaders with Strong Vision
29+
30+
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.
31+
32+
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.
33+
34+
<br>
35+
36+
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.
37+
38+
<br>
39+
40+
### How to upgrade to the Laravel community Rector package?
41+
42+
Add [new package](https://github.com/driftingly/rector-laravel) via composer:
43+
44+
```bash
45+
composer require driftingly/rector-laravel --dev
46+
```
47+
48+
<br>
49+
50+
**Big thanks to [Anthony Clark, aka driftingly](https://github.com/driftingly)** from Tighten for making this happen promptly and with a smooth swipe 🙏
51+
52+
<br>
53+
54+
### How to upgrade to the CakePHP community Rector package?
55+
56+
Add [new package](https://github.com/cakephp/upgrade) via composer:
57+
58+
```bash
59+
composer require cakephp/upgrade --dev
60+
```
61+
62+
<br>
63+
64+
That's it!
65+
66+
67+
<br>
68+
69+
We believe this brings faster iterations of the packages and focuses on a stronger Rector core to support their growth.

packages/Blog/FileSystem/PathAnalyzer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function detectDate(SmartFileInfo $fileInfo): ?DateTimeInterface
3838

3939
public function getSlug(SmartFileInfo $fileInfo): string
4040
{
41-
$date = $this->detectDate($fileInfo);
41+
$dateTime = $this->detectDate($fileInfo);
4242

43-
if (! $date instanceof \DateTimeInterface) {
43+
if (! $dateTime instanceof DateTimeInterface) {
4444
throw new ShouldNotHappenException();
4545
}
4646

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

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

56-
return $date->format('Y/m/d') . '/' . $match['name'];
56+
return $dateTime->format('Y/m/d') . '/' . $match['name'];
5757
}
5858
}

packages/Blog/Repository/PostRepository.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
public function getPosts(): array
3737
{
3838
$posts = $this->posts;
39-
return array_filter($posts, fn (Post $post): bool => ! $post->isDeprecated());
39+
return array_filter($posts, static fn(Post $post): bool => ! $post->isDeprecated());
4040
}
4141

4242
public function findBySlug(string $slug): ?Post
@@ -99,7 +99,7 @@ private function sortByDateTimeFromNewest(array $posts): array
9999
{
100100
usort(
101101
$posts,
102-
fn (Post $firstPost, Post $secondPost): int => $secondPost->getDateTime() <=> $firstPost->getDateTime()
102+
static fn(Post $firstPost, Post $secondPost): int => $secondPost->getDateTime() <=> $firstPost->getDateTime()
103103
);
104104

105105
return $posts;

packages/Blog/Twig/RoutingTwigExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ private function resolveCurrentRoute(Request $request): string
5656
{
5757
$currentRouteName = $request->get('_route');
5858

59-
return ltrim($currentRouteName, '/');
59+
return ltrim((string) $currentRouteName, '/');
6060
}
6161
}

packages/Blog/ValueObject/Post.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
private readonly ?string $updatedMessage = null,
2525
private readonly ?DateTimeInterface $deprecatedSince = null,
2626
private readonly ?string $deprecatedMessage = null,
27-
private readonly ?float $sinceRector = null
27+
private readonly ?string $sinceRector = null
2828
) {
2929
$this->plaintextContent = strip_tags($htmlContent);
3030
}
@@ -123,7 +123,7 @@ public function getUpdatedMessage(): ?string
123123
return $this->updatedMessage;
124124
}
125125

126-
public function getSinceRector(): ?float
126+
public function getSinceRector(): ?string
127127
{
128128
return $this->sinceRector;
129129
}

packages/Blog/ValueObjectFactory/PostFactory.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
8989
) : null;
9090
$deprecatedMessage = $configuration['deprecated_message'] ?? null;
9191

92+
$sinceRector = isset($configuration['since_rector']) ? (string) $configuration['since_rector'] : null;
93+
9294
return new Post(
9395
$id,
9496
$title,
@@ -103,7 +105,7 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
103105
$updatedMessage,
104106
$deprecatedSince,
105107
$deprecatedMessage,
106-
$configuration['since_rector'] ?? null
108+
$sinceRector
107109
);
108110
}
109111

@@ -116,11 +118,10 @@ public function createFromFileInfo(SmartFileInfo $smartFileInfo): Post
116118
*/
117119
private function decorateHeadlineWithId(string $htmlContent): string
118120
{
119-
return Strings::replace($htmlContent, self::HEADLINE_REGEX, function ($matches): string {
121+
return Strings::replace($htmlContent, self::HEADLINE_REGEX, static function ($matches) : string {
120122
$level = $matches['level'];
121123
$headline = $matches['headline'];
122124
$idValue = Strings::webalize($headline);
123-
124125
return sprintf('<h%d id="%s">%s</h%d>', $level, $idValue, $headline, $level);
125126
});
126127
}

packages/Demo/Error/ErrorMessageNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function normalize(string $errorMessage): string
2121
return $errorMessage;
2222
}
2323

24-
$type = ucfirst($match['type']);
24+
$type = ucfirst((string) $match['type']);
2525
$classLikeName = $match['class_like_name'];
2626
$classCode = lcfirst($type) . ' ' . $classLikeName . ' {}';
2727

src/Twig/TitleTwigExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ final class TitleTwigExtension extends AbstractExtension
1414
*/
1515
public function getFilters(): array
1616
{
17-
$twigFilter = new TwigFilter('clear_title', function (string $title): string {
17+
$twigFilter = new TwigFilter('clear_title', static function (string $title) : string {
1818
$clearTitle = strip_tags($title);
19-
2019
return str_replace('&nbsp;', ' ', $clearTitle);
2120
});
2221

src/Utils/StringsConverter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function camelCaseToGlue(string $input, string $glue): string
2323
$matches = Strings::matchAll($input, self::CAMEL_CASE_BY_WORD_REGEX);
2424
$parts = [];
2525
foreach ($matches as $match) {
26-
$parts[] = $match[0] === strtoupper((string) $match[0]) ? strtolower($match[0]) : lcfirst($match[0]);
26+
$parts[] = $match[0] === strtoupper((string) $match[0]) ? strtolower($match[0]) : lcfirst((string) $match[0]);
2727
}
2828

2929
return implode($glue, $parts);

0 commit comments

Comments
 (0)