Skip to content

Commit 8b79b6d

Browse files
committed
Merge branch 'master' of github.com:RefactoringGuru/design-patterns-php
2 parents 6782de1 + f86f21f commit 8b79b6d

File tree

15 files changed

+44
-24
lines changed

15 files changed

+44
-24
lines changed

ruleset.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="RefactoringGuruExamplesCodingStandard">
3+
<description>
4+
The RefactoringGuru coding standard.
5+
</description>
6+
7+
<rule ref="PSR2">
8+
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
9+
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
10+
11+
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments" />
12+
<exclude name="PSR2.Classes.PropertyDeclaration" />
13+
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine" />
14+
<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
15+
<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket" />
16+
17+
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore" />
18+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnNewLine" />
19+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
20+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace" />
21+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.OneParamPerLine" />
22+
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
23+
</rule>
24+
</ruleset>

src/RefactoringGuru/AbstractFactory/Structural/AbstractFactoryStructural.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ public function anotherUsefulFunctionB(AbstractProductA $collaborator): string
206206
*/
207207
function clientCode(AbstractFactory $factory)
208208
{
209-
$product_a = $factory->createProductA();
210-
$product_b = $factory->createProductB();
209+
$productA = $factory->createProductA();
210+
$productB = $factory->createProductB();
211211

212-
echo $product_b->usefulFunctionB() . "\n";
213-
echo $product_b->anotherUsefulFunctionB($product_a) . "\n";
212+
echo $productB->usefulFunctionB() . "\n";
213+
echo $productB->anotherUsefulFunctionB($productA) . "\n";
214214
}
215215

216216
/**

src/RefactoringGuru/Bridge/RealWorld/BridgeRealWorld.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ public function __construct(
144144
string $description,
145145
string $image,
146146
float $price
147-
)
148-
{
147+
) {
149148
$this->id = $id;
150149
$this->title = $title;
151150
$this->description = $description;

src/RefactoringGuru/Composite/RealWorld/CompositeRealWorld.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getData(): array
9999
* рендеринга, но мы можем с уверенностью предположить, что все они будут
100100
* возвращать строки.
101101
*/
102-
public abstract function render(): string;
102+
abstract public function render(): string;
103103
}
104104

105105
/**

src/RefactoringGuru/Composite/Structural/CompositeStructural.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function isComposite(): bool
8888
* умолчанию или поручить это конкретным классам, объявив метод, содержащий
8989
* поведение абстрактным.
9090
*/
91-
public abstract function operation(): string;
91+
abstract public function operation(): string;
9292
}
9393

9494
/**

src/RefactoringGuru/Composite/Structural/Output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ RESULT: Leaf
44
Client: Now I get a composite tree:
55
RESULT: Branch(Branch(Leaf+Leaf)+Branch(Leaf))
66

7-
Client: I can merge two components without checking their classes:
8-
RESULT: Branch(Branch(Leaf+Leaf)+Branch(Leaf)+Leaf)
7+
Client: I don't need to check the components classes even when managing the tree::
8+
RESULT: Branch(Branch(Leaf+Leaf)+Branch(Leaf)+Leaf)

src/RefactoringGuru/Decorator/RealWorld/DecoratorRealWorld.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,3 @@ function displayCommentAsAWebsite(InputFormat $format, string $text)
303303
"and filtering some dangerous HTML tags and attributes (safe, pretty):\n";
304304
displayCommentAsAWebsite($filteredInput, $dangerousForumPost);
305305
echo "\n\n\n";
306-

src/RefactoringGuru/Facade/RealWorld/FacadeRealWorld.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function saveAs(string $path): void { /* ... */ }
118118
*/
119119
class FFMpeg
120120
{
121-
static public function create(): FFMpeg { /* ... */ }
121+
public static function create(): FFMpeg { /* ... */ }
122122

123123
public function open(string $video): void { /* ... */ }
124124

src/RefactoringGuru/FactoryMethod/RealWorld/FactoryMethodRealWorld.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class SocialNetworkPoster
5858
* абстрактный коннектор. Это позволяет подклассам возвращать любые
5959
* конкретные коннекторы без нарушения контракта суперкласса.
6060
*/
61-
public abstract function getSocialNetwork(): SocialNetworkConnector;
61+
abstract public function getSocialNetwork(): SocialNetworkConnector;
6262

6363
/**
6464
* EN: When the factory method is used inside the Creator's business logic,

src/RefactoringGuru/FactoryMethod/Structural/FactoryMethodStructural.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class Creator
3434
* RU: Обратите внимание, что Создатель может также обеспечить реализацию
3535
* фабричного метода по умолчанию.
3636
*/
37-
public abstract function factoryMethod(): Product;
37+
abstract public function factoryMethod(): Product;
3838

3939
/**
4040
* EN: Also note that, despite its name, the Creator's primary

src/RefactoringGuru/Flyweight/RealWorld/FlyweightRealWorld.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ public function getVariation(
316316
string $texture,
317317
string $fur,
318318
string $size
319-
): CatVariation
320-
{
319+
): CatVariation {
321320
$key = $this->getKey(get_defined_vars());
322321

323322
if (! isset($this->variations[$key])) {

src/RefactoringGuru/State/Structural/StateStructural.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function setContext(Context $context)
9595
$this->context = $context;
9696
}
9797

98-
public abstract function handle1(): void;
98+
abstract public function handle1(): void;
9999

100-
public abstract function handle2(): void;
100+
abstract public function handle2(): void;
101101
}
102102

103103
/**

src/RefactoringGuru/TemplateMethod/RealWorld/TemplateMethodRealWorld.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public function post(string $message): bool
8282
* RU: Шаги объявлены абстрактными, чтобы заставить подклассы реализовать их
8383
* полностью.
8484
*/
85-
public abstract function logIn(string $userName, string $password): bool;
85+
abstract public function logIn(string $userName, string $password): bool;
8686

87-
public abstract function sendData(string $message): bool;
87+
abstract public function sendData(string $message): bool;
8888

89-
public abstract function logOut(): void;
89+
abstract public function logOut(): void;
9090
}
9191

9292
/**

src/RefactoringGuru/TemplateMethod/Structural/TemplateMethodStructural.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ protected function baseOperation3(): void
7373
*
7474
* RU: А эти операции должны быть реализованы в подклассах.
7575
*/
76-
protected abstract function requiredOperations1(): void;
76+
abstract protected function requiredOperations1(): void;
7777

78-
protected abstract function requiredOperation2(): void;
78+
abstract protected function requiredOperation2(): void;
7979

8080
/**
8181
* EN: These are "hooks." Subclasses may override them, but it's not

src/RefactoringGuru/Visitor/RealWorld/VisitorRealWorld.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,3 @@ public function visitEmployee(Employee $employee): string
278278

279279
// $export = new JSONExport; 
280280
// echo $company->accept($export);
281-

0 commit comments

Comments
 (0)