Skip to content

Instantly share code, notes, and snippets.

View vudaltsov's full-sized avatar
🐘

Valentin Udaltsov vudaltsov

🐘
View GitHub Profile
@vudaltsov
vudaltsov / test.php
Last active April 5, 2021 21:03
sqlite vs vimeo/php-mysql-engine
<?php
declare(strict_types=1);
require_once __DIR__.'/vendor/autoload.php';
const ITERATIONS = 10_000;
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$event = $stopwatch->start('db');
@vudaltsov
vudaltsov / Interpolator.php
Last active June 3, 2022 18:37
PHP Interpolator
<?php
declare(strict_types=1);
final class Interpolator
{
public function __construct(
private string $format = '%s',
) {
}
<?php
declare(strict_types=1);
namespace HappyInc\Infrastructure\Migrations;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@vudaltsov
vudaltsov / php_errors.yaml
Created February 14, 2022 18:47
Symfony php_errors config
framework:
php_errors:
log:
!php/const E_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_WARNING: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_PARSE: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_NOTICE: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_CORE_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_CORE_WARNING: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_COMPILE_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
<?php
/**
* @psalm-pure
* @template T
* @template TArray of array<T>
* @param TArray $values
* @return (TArray is non-empty-array<T> ? T : ?T)
*/
function array_value_first(array $values): mixed
@vudaltsov
vudaltsov / basic_functions.php
Last active May 12, 2022 12:59
PHP facade functions examples
<?php
declare(strict_types=1);
/**
* @throws JsonException
*/
function jsonEncode(mixed $data, int $flags = 0): string
{
return json_encode($data, $flags | JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
<?php
declare(strict_types=1);
namespace HappyInc\Infrastructure;
/**
* @psalm-pure
*/
function mb_ucfirst(string $string): string
<?php
declare(strict_types=1);
use HappyInc\Tool\Rector\ReadOnlyPublicPropertyRector;
use HappyInc\Tool\Rector\UuidTRector;
use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
@vudaltsov
vudaltsov / Message.php
Created December 31, 2022 03:41
Envelope
<?php
/**
* @psalm-immutable
* @template TResult
*/
interface Message
{
}
@vudaltsov
vudaltsov / Makefile
Created January 9, 2023 15:45
WaitCommand.php
vendor: composer.json composer.lock
composer install
touch vendor
db: vendor
php bin/console wait $(DB_HOST):$(DB_PORT)
php bin/console doctrine:database:create --if-not-exists
php bin/console doctrine:migrations:migrate --no-interaction
.PHONY: db