Skip to content

Instantly share code, notes, and snippets.

<?php
// Imagine you have a class that memoizes some data statically (let's assume
// the data is computationally expensive to load)
class ExpensiveDataHelper
{
protected static $expensive_data = null;
public function getExpensiveData()
<?php
namespace Tests\Project;
use RecursiveCallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Tests\Constraints;
use Tests\TestCase;
<?php
use Illuminate\Support\Facades\Gate;
use RuntimeException;
/**
* @template M
*/
trait HasRouteBoundModel
{
<scheme name="Light - Minimal Color" version="142" parent_scheme="Default">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2022-04-18T10:59:54</property>
<property name="ide">PhpStorm</property>
<property name="ideVersion">2022.1.0.0</property>
<property name="modified">2022-04-18T11:00:13</property>
<property name="originalScheme">Light - Minimal Color</property>
</metaInfo>
<console-font>
<?php
class MonthlyPlan
{
public int $length = 1;
public string $unit = 'month';
public function normalizeBillingPeriod(Subscription $subscription, Carbon $charge_at): array
{
// First, we'll naively compute the end of the billing period (assuming the timing is 100% accurate)
File 1:
REMOVE: LegacyRecord::each(function($record) {
ADD: LegacyRecord::with('new_record')->each(function($record) {
$identity = ['legacy_id' => $record->id];
$values = $this->transformLegacyRecord($record);
REMOVE: NewRecord::updateOrCreate($identity, $values);
ADD: $new_record = $record->new_record ?? NewRecord::make($identity);
ADD: $new_record->fill($this->transformLegacyRecord($record));
<?php
namespace App\Support;
use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use Illuminate\Testing\Assert;
trait ShouldBeMocked
@inxilpro
inxilpro / .editorconfig
Last active February 9, 2022 21:52
Laravel PhpStorm Code Style Config
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
<?php
class ArticleController
{
public function show(Request $request, Article $article)
{
// Set up a response and add last modified and/or ETag data
$response = response()
->setLastModified($article->updated_at)
->setEtag(md5($article->body), true);
<?php
$data = [
'a2' => null,
'a3' => '',
'a4' => [],
'b2' => null,
'b3' => '',
'b4' => [],
'c2' => null,