Skip to content

Instantly share code, notes, and snippets.

View asgrim's full-sized avatar
😈
Doing evil things, probably. Sorry...

James Titcumb asgrim

😈
Doing evil things, probably. Sorry...
View GitHub Profile

Best practices for crafting high quality PHP apps

This prototype works, but it’s not pretty, and now it’s in production. That legacy application really needs some TLC. Where do we start? When creating long lived applications, it’s imperative to focus on good practices. The solution is to improve the whole development life cycle; from planning, better coding and testing, to automation, peer review and more. In this tutorial, we’ll take a deep dive into each of these areas, looking at how we can make positive, actionable change in our workflow.

This workshop intends to improve your skills in planning, documenting, some aspects of development, testing and delivery of software for both legacy and greenfield projects. The workshop is made up of multiple exercises, allowing dynamic exploration into the various aspects of the software development life cycle. In each practical exercise, we'll brainstorm and investigate solutions, ensuring they are future-proofed, well tested and lead to the ultimate goal of conf

<?php
class x {
async public function highlightFileContents($path) : string {
$source = await Amp\File\get($path);
return highlight_string($source, true);
}
}
$highlighted = Amp\wait((new x())->highlightFileContents("helpers.php"));
<?php
class x {
async static function highlightFileContents($path) {
$source = await Amp\File\get($path);
return highlight_string($source, true);
}
}
$highlighted = Amp\wait(x::highlightFileContents("helpers.php"));
@asgrim
asgrim / app.php
Last active May 1, 2017 15:13
Example for using `ciaranmcnulty/behat-psr7extension` with a Zend Expressive app
<?php
declare(strict_types=1);
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/** @var \Interop\Container\ContainerInterface $container */
$container = require __DIR__ . '/../config/container.php';
/** @var \Zend\Expressive\Application $app */
<?php
$months = array_map(
function ($i) {
return (new \DateTimeImmutable())->setDate(2017, $i, 1)->format('F');
},
range(1, 12)
);
var_dump($months);
@asgrim
asgrim / pre-commit
Created December 31, 2015 11:46
Never commit a broken test again...
#!/bin/bash
echo -n "Running phpunit... "
vendor/bin/phpunit --stop-on-failure --stop-on-error > /dev/null
if [ $? -ne 0 ]
then
echo "[FAILED]"
exit 1
fi
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use BetterReflection\Reflector\ClassReflector;
use BetterReflection\SourceLocator\AggregateSourceLocator;
use BetterReflection\SourceLocator\SingleFileSourceLocator;
use PhpParser\PrettyPrinter\Standard as CodePrinter;
// Create the reflection first (without loading)
<?php
$hellos = ['hi', 'hey'];
$separators = [
' ',
', ',
' - ',
'... ',
'.. ',