Skip to content

Instantly share code, notes, and snippets.

View Majkl578's full-sized avatar
💥
breaking builds

Michael Moravec Majkl578

💥
breaking builds
View GitHub Profile
@Majkl578
Majkl578 / typed-property.php
Last active June 5, 2019 12:31
model example for typed properties
<?php
declare(strict_types=1);
final class Foo
{
var DateTimeImmutable $createdAt {
get;
private set(DateTimeImmutable $value) : void {
assert($this->createdAt === null, "Can't change time of creation.");
@Majkl578
Majkl578 / ArbitraryRun.php
Last active September 10, 2018 12:26
typed factory
<?php
declare(strict_Types=1);
namespace Example;
(function () : void {
$requestFactory = new class implements ServerRequestFactory {
public function __invoke() : ServerRequest
{
<?php
$hello = 'Hello';
$world = 'World';
$speaker = new class use ($hello as public, $world as private $who) {
public function say() : void
{
echo $this->hello . ' ' $this->who, PHP_EOL;
}
@Majkl578
Majkl578 / Comparable.php
Last active October 30, 2018 13:25
Equatable + Comparable
<?php
declare(strict_types=1);
namespace Comparison;
/**
* This interface imposes a total ordering on the objects of each class that implements it.
* This ordering is referred to as the class's natural ordering, and the class's compareTo method
* is referred to as its natural comparison method.
$ vendor/bin/roave-backward-compatibility-check r:a --from=v1.7.2 --to=master -- lib
Comparing from 3e7656c5adfd9b7d0d8757aa1e9e8daf43a6f200 to bba2123d7d8ab43927ff2370a4785892b7c181d5...
Loading composer repositories with package information
Updating dependencies
Package operations: 13 installs, 0 updates, 0 removals
- Installing ocramius/package-versions (1.3.0): Loading from cache
- Installing zendframework/zend-eventmanager (3.2.1): Loading from cache
- Installing zendframework/zend-code (3.3.0): Loading from cache
- Installing ocramius/proxy-manager (2.2.0): Loading from cache
- Installing symfony/polyfill-mbstring (v1.8.0): Loading from cache
> Annotations
> > Annotation
> > > Reference {"identifier":"Annot","fully_qualified":false}
> > > Parameters
> > > > Parameter\NamedParameter
> > > > > Scalar\Identifier {"value":"v1"}
> > > > > Collection\ListCollection
> > > > > > Scalar\IntegerScalar {"value":1}
> > > > > > Scalar\IntegerScalar {"value":2}
> > > > > > Scalar\IntegerScalar {"value":3}
@Majkl578
Majkl578 / 100
Created April 27, 2018 18:15
Doctrine logo ASCII
+----------------------------------------------------------------------------------------------------+
|oooooooooooooooooooooooooo:: ...:ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooo.. .::oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooo:. .:oooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooo: .:oooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooo ..oooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooo: .:oooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooo. ..oooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooo :oooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooo: .oooooooooooooooooooooooooooooooooooooooo
<?php
new class
{
public function __construct()
{
$s = microtime(true);
for ($i = 0; $i < 100000000; $i++) {
(function () {})();
@Majkl578
Majkl578 / assert.php
Created April 11, 2018 01:37
signature misuse + func_get_args() vs. assert() + count() @ PHP 7.2
<?php
function foo(int ...$prices)
{
assert(count($prices) > 0);
}
$t = microtime(true);
for ($i = 0; $i < 10000000; $i++) {

Keybase proof

I hereby claim:

  • I am majkl578 on github.
  • I am majkl (https://keybase.io/majkl) on keybase.
  • I have a public key ASBoeRpsENPXRp5PvnaxBaoeKzodCPdO3Q5JA5WA1hfT7wo

To claim this, I am signing this object: