Skip to content

Instantly share code, notes, and snippets.

View Ocramius's full-sized avatar
In your repositories, watching your code. Always watching.

Marco Pivetta Ocramius

In your repositories, watching your code. Always watching.
View GitHub Profile
Ocramius / heap-object.h
Created April 8, 2024 14:24 — forked from oplanre/heap-object.h
PHP Typesystem Extended (C++). This is part of a project i built at work to make it easier/more stable to build php extensions
#pragma once
#include "lend-forward.h"
#include "lend-type.h" // NOLINT(build/include_directory)
#include "lend-internal.h" // NOLINT(build/include_directory)
#include "lend-handle.h" // NOLINT(build/include_directory)
#include "lendconfig.h" // NOLINT(build/include_directory)
#include <cstdint>
namespace lend {
* @class HeapObject
Ocramius /
Created March 28, 2023 09:13
`compact()` function in PHP, and why it is problematic due to its magic behavior

compact() is a problematic construct that breaks the direct code link between variable definition and variable consumption.

$someVar = 123;

return compact('someVar');

This is equivalent to

Ocramius /
Last active March 17, 2023 12:06
Handling optional input parameters in PHP with `vimeo/psalm` and `azjezz/psl`

Handling optional input parameters in PHP with vimeo/psalm and azjezz/psl

I had an interesting use-case with a customer for which I provide consulting services: they needed multiple fields to be marked as "optional".

Example: updating a user

We will take a CRUD-ish example, for the sake of simplicity.

For example, in the following scenario, does a null $description mean "remove the description",

Ocramius /
Created October 7, 2022 08:38
Git-flow vs GitHub-flow

Git-flow vs GitHub-flow

What we want

A list of requirements:

  • stakeholders expect a list of provided features, every few days, in a human-friendly report
  • every change must have been reviewed, before being deployed
  • every change must have passed our automated checks, before being deployed
  • every change must have been verified by QA staff, before being deployed
Ocramius /
Created October 7, 2022 08:31
A healthy git-flow (if you can call git-flow healthy at all), in which `master` is correctly merged back to `develop`
git checkout -b master
git log -1
# commit 65345471c1040ceb90b1817d7427d58d7b09fdca (HEAD -> master)
git checkout -b develop
git log -1
# both branches are at the same ref:
# commit 65345471c1040ceb90b1817d7427d58d7b09fdca (HEAD -> develop, master)
echo "a feature" > feature.txt
Ocramius /
Last active February 24, 2023 10:25
Script to check whether `psalm-baseline.xml` improved/worsened over time
#!/usr/bin/env bash
git show "$TARGET_REF:psalm-baseline.xml" | xmllint --xpath 'count(//file[not(starts-with(@src, "test"))]/*/code)' -
namespace Tests\Integration;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionProperty;
use Webmozart\Assert\Assert;
Ocramius / Day.php
Created April 3, 2020 14:13
Example abstraction that only allows a resolution of "day" for time inside a specific business domain
namespace Core\Domain\Time;
use DateTimeImmutable;
use DateTimeZone;
use Generator;
use Iterator;
Ocramius / psalm-compendium.php
Last active November 9, 2023 07:27
A small compendium of what is possible with `vimeo/psalm` 3.9.x to add some decent type system features to PHP
// -- types are a compile-time propagated concept
class TheType
/** @var string */
public $foo = 'bar';
#!/usr/bin/env php
namespace WaitForElasticsearch;
use InvalidArgumentException;
use UnexpectedValueException;
use function curl_close;