This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$right = $this->invert($tree->getLeft()); | |
$left = $this->invert($tree->getRight()); | |
return new Node($tree->getValue(), $left, $right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($tree === null) { | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function invert(?Node $tree): ?Node | |
{ | |
if ($tree === null) { | |
return null; | |
} | |
$right = $this->invert($tree->getLeft()); | |
$left = $this->invert($tree->getRight()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function invert(Node $tree): Node | |
{ | |
$right = $tree->getLeft(); | |
$left = $tree->getRight(); | |
return new Node($tree->getValue(), $left, $right); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$level3al = new Node('deepAL', null, null); | |
$level3ar = new Node('deepAR', null, null); | |
$level3bl = new Node('deepBL', null, null); | |
$level3br = new Node('deepBR', null, null); | |
$level2a = new Node('midA', $level3al, $level3ar); | |
$level2b = new Node('midB', $level3bl, $level3br); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Node | |
{ | |
private $value; | |
private $left; | |
private $right; | |
public function __construct(string $value, ?Node $left, ?Node $right) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
final class CustomerName | |
{ | |
private $firstName; | |
private $lastName; | |
public function __construct(string $firstName, string $lastName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function setFirstName(string $firstName): CustomerName | |
{ | |
return new self($firstName, $this->lastName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function __construct(string $firstName, string $lastName) | |
{ | |
Assert::stringNotEmpty($firstName); | |
Assert::stringNotEmpty($lastName); | |
Assert::alpha($firstName); | |
Assert::alpha($lastName); | |
$this->firstName = $firstName; | |
$this->lastName = $lastName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function sendMail( | |
CustomerName $customerName, | |
Email $email | |
): void | |
{ | |
$mail = new Mail($customerName->fullName(), $email); | |
// send mail | |
} |
NewerOlder