Skip to content

Instantly share code, notes, and snippets.

View BackEndTea's full-sized avatar

Gert de Pagter BackEndTea

View GitHub Profile
<?php
class WebsiteContext{}
class WrongSendMail
{
public function __construct(private WebsiteContext $website) {}
public function send(int $emailId) {}
@BackEndTea
BackEndTea / Email.php
Created December 2, 2022 11:41
VO with possible invalid state
<?php
namespace Email;
interface EmailAddress {
public function isValid(): bool;
public function asString(): string;
}
class ValidEmailAddress implements EmailAddress {
<?php
function connect_while(ApiClient $client): string
{
$tries = 0;
while(true) {
$tries++;
try {
$result = $client->doThing();
<?php
// OPTION A:
class MyController
{
//constructor, properties etc
/**
* @Route("/my/path")
*/
<?php
// Entity
/**
* @ORM\Repository(DoctrinePricesRepository::class)
*/
class Price {
public function __construct(
@BackEndTea
BackEndTea / arr.php
Last active March 13, 2021 18:31
array of strings to int
<?php
/**
* @param array<string> $in
*
* @return array<int>
*/
function withIntval(array $in): array
{
return array_map('intval', $in);
}
interface Foo {
foo(): void;
}
// One
type FooBag = {
one: Foo,
two: Foo,
three: Foo
};
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
class AccountPageActionV1
{
function env(string $param): string
{
return sprintf('%env(%s)%', $param);
}
@BackEndTea
BackEndTea / TraversalTest.php
Created January 3, 2021 12:07
Traversal Test
<?php
final class TraversalTest extends TestCase
{
public function testTraversal(): void
{
$parser = new TokenParser(new Lexer());
$ast = $parser->parse('/foo|bar{2,}/i');
$traverser = new Traverser([new RemoveQuantifierVisitor()]);