Skip to content

Psr12 code style fix #41

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

Merged
merged 4 commits into from
Jul 26, 2025
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 change: 0 additions & 1 deletion src/RefactoringGuru/AbstractFactory/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ public function render(string $templateString, array $arguments = []): string
*/
class Page
{

public $title;

public $content;
Expand Down
6 changes: 4 additions & 2 deletions src/RefactoringGuru/Adapter/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ function clientCode(Notification $notification)
{
// ...

echo $notification->send("Website is down!",
echo $notification->send(
"Website is down!",
"<strong style='color:red;font-size: 50px;'>Alert!</strong> " .
"Our website is not responding. Call admins and bring it up!");
"Our website is not responding. Call admins and bring it up!"
);

// ...
}
Expand Down
37 changes: 28 additions & 9 deletions src/RefactoringGuru/Bridge/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public function view(): string
$this->renderer->renderTitle($this->product->getTitle()),
$this->renderer->renderTextBlock($this->product->getDescription()),
$this->renderer->renderImage($this->product->getImage()),
$this->renderer->renderTextBlock('$'.number_format($this->product->getPrice(), 2)),
$this->renderer->renderLink("/cart/add/".$this->product->getId(), "Add to cart"),
$this->renderer->renderTextBlock('$' . number_format($this->product->getPrice(), 2)),
$this->renderer->renderLink("/cart/add/" . $this->product->getId(), "Add to cart"),
$this->renderer->renderFooter()
]);
}
Expand Down Expand Up @@ -154,15 +154,30 @@ public function __construct(
$this->price = $price;
}

public function getId(): string { return $this->id; }
public function getId(): string
{
return $this->id;
}

public function getTitle(): string { return $this->title; }
public function getTitle(): string
{
return $this->title;
}

public function getDescription(): string { return $this->description; }
public function getDescription(): string
{
return $this->description;
}

public function getImage(): string { return $this->image; }
public function getImage(): string
{
return $this->image;
}

public function getPrice(): float { return $this->price; }
public function getPrice(): float
{
return $this->price;
}
}


Expand Down Expand Up @@ -326,9 +341,13 @@ function clientCode(Page $page)
echo "\n\n";


$product = new Product("123", "Star Wars, episode1",
$product = new Product(
"123",
"Star Wars, episode1",
"A long time ago in a galaxy far, far away...",
"/images/star-wars.jpeg", 39.95);
"/images/star-wars.jpeg",
39.95
);

$page = new ProductPage($HTMLRenderer, $product);
echo "HTML view of a product page, same client code:\n";
Expand Down
6 changes: 4 additions & 2 deletions src/RefactoringGuru/Command/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ class Queue

public function __construct()
{
$this->db = new \SQLite3(__DIR__ . '/commands.sqlite',
SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$this->db = new \SQLite3(
__DIR__ . '/commands.sqlite',
SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE
);

$this->db->query('CREATE TABLE IF NOT EXISTS "commands" (
"id" INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
Expand Down
8 changes: 6 additions & 2 deletions src/RefactoringGuru/Composite/Conceptual/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ public function getParent(): Component
* во время сборки дерева объектов. Недостаток такого подхода в том, что эти
* методы будут пустыми для компонентов уровня листа.
*/
public function add(Component $component): void { }
public function add(Component $component): void
{
}

public function remove(Component $component): void { }
public function remove(Component $component): void
{
}

/**
* EN: You can provide a method that lets the client code figure out whether
Expand Down
10 changes: 5 additions & 5 deletions src/RefactoringGuru/Composite/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ public function setData($data): void
public function getData(): array
{
$data = [];

foreach ($this->fields as $name => $field) {
$data[$name] = $field->getData();
}

return $data;
}

Expand All @@ -220,11 +220,11 @@ public function getData(): array
public function render(): string
{
$output = "";

foreach ($this->fields as $name => $field) {
$output .= $field->render();
}

return $output;
}
}
Expand All @@ -244,7 +244,7 @@ public function render(): string
// RU: Обратите внимание, как комбинированный результат рендеринга
// потомков включается в тег fieldset.
$output = parent::render();

return "<fieldset><legend>{$this->title}</legend>\n$output</fieldset>\n";
}
}
Expand Down
45 changes: 36 additions & 9 deletions src/RefactoringGuru/Facade/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ public function downloadVideo(string $url): void
*/
class YouTube
{
public function fetchVideo(): string { /* ... */ }
public function fetchVideo(): string
{
/* ... */
}

public function saveAs(string $path): void { /* ... */ }
public function saveAs(string $path): void
{
/* ... */
}

// EN: ...more methods and classes...
//
Expand All @@ -118,24 +124,45 @@ public function saveAs(string $path): void { /* ... */ }
*/
class FFMpeg
{
public static function create(): FFMpeg { /* ... */ }
public static function create(): FFMpeg
{
/* ... */
}

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

// ...more methods and classes... RU: ...дополнительные методы и классы...
}

class FFMpegVideo
{
public function filters(): self { /* ... */ }
public function filters(): self
{
/* ... */
}

public function resize(): self { /* ... */ }
public function resize(): self
{
/* ... */
}

public function synchronize(): self { /* ... */ }
public function synchronize(): self
{
/* ... */
}

public function frame(): self { /* ... */ }
public function frame(): self
{
/* ... */
}

public function save(string $path): self { /* ... */ }
public function save(string $path): self
{
/* ... */
}

// ...more methods and classes... RU: ...дополнительные методы и классы...
}
Expand Down
14 changes: 10 additions & 4 deletions src/RefactoringGuru/Flyweight/Conceptual/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ public function listFlyweights(): void
// ...

function addCarToPoliceDatabase(
FlyweightFactory $ff, $plates, $owner,
$brand, $model, $color
FlyweightFactory $ff,
$plates,
$owner,
$brand,
$model,
$color
) {
echo "\nClient: Adding a car to database.\n";
$flyweight = $ff->getFlyweight([$brand, $model, $color]);
Expand All @@ -146,15 +150,17 @@ function addCarToPoliceDatabase(
$flyweight->operation([$plates, $owner]);
}

addCarToPoliceDatabase($factory,
addCarToPoliceDatabase(
$factory,
"CL234IR",
"James Doe",
"BMW",
"M5",
"red",
);

addCarToPoliceDatabase($factory,
addCarToPoliceDatabase(
$factory,
"CL234IR",
"James Doe",
"BMW",
Expand Down
5 changes: 3 additions & 2 deletions src/RefactoringGuru/Flyweight/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function __construct(
* не быть объявленного класса Контекста. Контекстные данные могут храниться
* в массиве или какой-то другой, более эффективной структуре данных.
*/
public function renderProfile(string $name, string $age, string $owner)
public function renderProfile(string $name, string $age, string $owner)
{
echo "= $name =\n";
echo "Age: $age\n";
Expand Down Expand Up @@ -305,7 +305,8 @@ public function addCat(
*/
public function getVariation(
string $breed,
string $image, $color,
string $image,
string $color,
string $texture,
string $fur,
string $size
Expand Down
8 changes: 6 additions & 2 deletions src/RefactoringGuru/Singleton/Conceptual/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ class Singleton
* RU: Конструктор Одиночки всегда должен быть скрытым, чтобы предотвратить
* создание объекта через оператор new.
*/
protected function __construct() { }
protected function __construct()
{
}

/**
* EN: Singletons should not be cloneable.
*
* RU: Одиночки не должны быть клонируемыми.
*/
protected function __clone() { }
protected function __clone()
{
}

/**
* EN: Singletons should not be restorable from strings.
Expand Down
11 changes: 8 additions & 3 deletions src/RefactoringGuru/Singleton/RealWorld/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ class Singleton
* RU: Конструктор Одиночки не должен быть публичным. Однако он не может
* быть приватным, если мы хотим разрешить создание подклассов.
*/
protected function __construct() { }
protected function __construct()
{
}

/**
* EN: Cloning and unserialization are not permitted for singletons.
*
* RU: Клонирование и десериализация не разрешены для одиночек.
*/
protected function __clone() { }
protected function __clone()
{
}

public function __wakeup()
{
Expand Down Expand Up @@ -215,7 +219,8 @@ public function setValue(string $key, string $value): void
//
// RU: ...и восстанавливает их.
$config2 = Config::getInstance();
if ($login == $config2->getValue("login") &&
if (
$login == $config2->getValue("login") &&
$password == $config2->getValue("password")
) {
Logger::log("Config singleton also works fine.");
Expand Down
38 changes: 38 additions & 0 deletions src/RefactoringGuru/State/RealWorld/Output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=== Invoice State Pattern Demo ===

Created invoice: {"id":1001,"amount":1500,"state":"draft","created_at":"2025-07-12 13:14:15"}

--- Scenario 1: Draft -> Open -> Paid ---
Invoice #1001 finalized - changing from Draft to Open
Current state: open
Invoice #1001 paid - changing from Open to Paid
Current state: paid
Expected error: Cannot pay invoice in paid state

--- Scenario 2: Draft -> Open -> Void ---
Invoice #1002 finalized - changing from Draft to Open
Invoice #1002 voided - changing from Open to Void
Invoice 2 state: void

--- Scenario 3: Draft -> Open -> Uncollectable -> Paid ---
Invoice #1003 finalized - changing from Draft to Open
Invoice #1003 cancelled - changing from Open to Uncollectable
Invoice 3 state: uncollectable
Invoice #1003 paid - changing from Uncollectable to Paid
Invoice 3 final state: paid

--- Scenario 4: Draft -> Open -> Uncollectable -> Void ---
Invoice #1004 finalized - changing from Draft to Open
Invoice #1004 cancelled - changing from Open to Uncollectable
Invoice #1004 voided - changing from Uncollectable to Void
Invoice 4 final state: void

--- Error Scenario: Invalid transition ---
Expected error: Cannot pay invoice in draft state

--- State Information ---
Invoice 1: {"id":1001,"amount":1500,"state":"paid","created_at":"2025-07-12 13:14:15"}
Invoice 2: {"id":1002,"amount":750,"state":"void","created_at":"2025-07-12 13:14:15"}
Invoice 3: {"id":1003,"amount":2000,"state":"paid","created_at":"2025-07-12 13:14:15"}
Invoice 4: {"id":1004,"amount":500,"state":"void","created_at":"2025-07-12 13:14:15"}
Invoice 5: {"id":1005,"amount":300,"state":"draft","created_at":"2025-07-12 13:14:15"}
Loading