if ($context !== $result) { $downContext = $downContext->copy(); } $downContext->copyProperties($result); self::copyStep($downContext, $result); self::copyNegativeUnits($downContext, $result); return $downContext->settings($result->getSettings()); } if ($downContext instanceof CarbonPeriod && $result instanceof CarbonPeriod) { if ($context !== $result) { $downContext = $downContext->copy(); } return $downContext ->setDates($result->getStartDate(), $result->getEndDate()) ->setRecurrences($result->getRecurrences()) ->setOptions($result->getOptions()) ->settings($result->getSettings()); } return $result; }); } } private static function getAnonymousClassCodeForTrait(string $trait) { return 'return new class() extends '.static::class.' {use '.$trait.';};'; } private static function getMixableMethods(self $context): Generator { foreach (get_class_methods($context) as $name) { if (method_exists(static::class, $name)) { continue; } yield $name; } } /** * Stack a Carbon context from inside calls of self::this() and execute a given action. * * @param static|null $context * @param callable $callable * * @throws Throwable * * @return mixed */ protected static function bindMacroContext($context, callable $callable) { static::$macroContextStack[] = $context; try { return $callable(); } finally { array_pop(static::$macroContextStack); } } /** * Return the current context from inside a macro callee or a null if static. * * @return static|null */ protected static function context() { return end(static::$macroContextStack) ?: null; } /** * Return the current context from inside a macro callee or a new one if static. * * @return static */ protected static function this() { return end(static::$macroContextStack) ?: new static(); } } 🧨 Trait "Carbon\Traits\Mixin" not found