Skip to content

Instantly share code, notes, and snippets.

View inxilpro's full-sized avatar

Chris Morrell inxilpro

View GitHub Profile
<?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,
<?php
Str::macro('spellOutNumbers', static function($value, $locale = 'en_us') {
$separatorFormatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
$groupingSeparator = preg_quote($separatorFormatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL), '/');
$decimalSeparator = preg_quote($separatorFormatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL), '/');
$spellOutFormatter = new \NumberFormatter($locale, \NumberFormatter::SPELLOUT);
return preg_replace_callback(
@inxilpro
inxilpro / JsString.php
Created September 30, 2021 19:15
Javascript string implementation for Laravel
<?php
namespace App\Support;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Support\Str;
class JsString implements Htmlable
// This is a definition for the Monarch tokenizer (used by Monaco) to syntax
// highlight Symfony Expression Language.
//
// See these links for more details:
// https://microsoft.github.io/monaco-editor/monarch.html
// https://symfony.com/doc/current/components/expression_language/syntax.html
export default {
defaultToken: 'invalid',
<?php
namespace App\Console\Commands\Utilities;
use Closure;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\RequestException;