Skip to content

Instantly share code, notes, and snippets.

<?php
class Author
{
private $id, $membership, $posts = [];
// Pseudo code 1
public function __construct($id, $membership, $posts)
<?php
/**
* A better way to iterate over an collection
*/
$itemsArray = [ 1, 2, 3 ];
/**
* Legacy code
DELIMITER $$
CREATE TRIGGER Prevent_User_From_Insert_Empty_Strings BEFORE INSERT ON users
FOR EACH ROW
BEGIN
   IF NEW.name = '' THEN
       SIGNAL SQLSTATE '45000';
   END IF;
END;

File: tests/TestCase.php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
 use CreatesApplication;

This code snippet overrides php DuskTestCase->createBrowsers method to extends the functionality and add the elements count assertion

File tests/Browser/BaseBrowser.php

// Extend Browser Class
namespace Tests\Browser;

use Laravel\Dusk\Browser;
use PHPUnit_Framework_Assert as PHPUnit;
@nezarfadle
nezarfadle / simple_php_template_engine.md
Last active May 26, 2017 08:43
How to use PHP Closure to write a simple template engine

File: index.php

class Article
{
    private $title = "This is an article";
}
umask (002)
0 0 2 = 000 000 010
Not 0 0 2 = 111 111 101
110 110 110 AND
111 111 101 =
110 110 100
rw- rw- r--
############
umask (022)
<?php

class CacheDecorater
{
    function decorate( $tweet )   
    {
        $tweet->cached = true;
        return $tweet;
    }
use Illuminate\Http\JsonResponse; 

class JsonEmptyResponse extends JsonResponse 
{ 
     
    public function __construct() 
    { 
         
        $data = [