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
Ocramius / Rand.php
Created April 14, 2011 13:23
MySQL RAND() function in Doctrine2 DQL
View Rand.php
<?php
namespace My\Custom\Doctrine2\Function;
/**
* RandFunction ::= "RAND" "(" ")"
*/
class Rand extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser)
@Ocramius
Ocramius / git-flow_vs_github-flow.md
Created October 7, 2022 08:38
Git-flow vs GitHub-flow
View git-flow_vs_github-flow.md

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
Ocramius / psalm-compendium.php
Last active July 12, 2023 23:19
A small compendium of what is possible with `vimeo/psalm` 3.9.x to add some decent type system features to PHP
View psalm-compendium.php
<?php
// -- types are a compile-time propagated concept
// https://psalm.dev/r/338f74a96c
class TheType
{
/** @var string */
public $foo = 'bar';
}
@Ocramius
Ocramius / User.php
Last active June 29, 2023 15:01
Doctrine 2 ManyToMany - the correct way
View User.php
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity()
* @ORM\Table(name="user")
*/
class User
@Ocramius
Ocramius / compact-in-php-a-problematic-construct.md
Created March 28, 2023 09:13
`compact()` function in PHP, and why it is problematic due to its magic behavior
View compact-in-php-a-problematic-construct.md

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
Ocramius / handling-optional-input-fields-with-type-safe-abstractions.md
Last active March 17, 2023 12:06
Handling optional input parameters in PHP with `vimeo/psalm` and `azjezz/psl`
View handling-optional-input-fields-with-type-safe-abstractions.md
@Ocramius
Ocramius / Caddyfile
Last active March 12, 2023 12:58
Example docker + docker-compose + caddy + traefik setup that routes to multiple apps from one exposed HTTP port
View Caddyfile
:80 {
root /serve
}
@Ocramius
Ocramius / check-source-baseline-size.sh
Last active February 24, 2023 10:25
Script to check whether `psalm-baseline.xml` improved/worsened over time
View check-source-baseline-size.sh
#!/usr/bin/env bash
export TARGET_REF=${TARGET_REF:-HEAD}
git show "$TARGET_REF:psalm-baseline.xml" | xmllint --xpath 'count(//file[not(starts-with(@src, "test"))]/*/code)' -
@Ocramius
Ocramius / .gitignore
Last active January 10, 2023 16:34
`Zend\EventManager` examples
View .gitignore
vendor
composer.lock
@Ocramius
Ocramius / healthy-git-flow.sh
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`
View healthy-git-flow.sh
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