Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions code-quality/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

<rule ref="PSR12"/>

<rule ref="Generic.Formatting.SpaceAfterNot">
<properties>
<property name="spacing" value="1"/>
</properties>
</rule>

<rule ref="Generic.Formatting.SpaceAfterCast">
<properties>
<property name="spacing" value="1"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Classes.ClassStructure">
<properties>
<property name="groups" type="array">
Expand Down
4 changes: 3 additions & 1 deletion code-quality/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ parameters:
level: 9
paths:
- ../src
- ../private-classes
- ../private-classes
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
14 changes: 7 additions & 7 deletions private-classes/Blade/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function applyExtensionCallback(string $template): string
// Removes all parts like: "{{--Comment--}}".
protected function removeComments(string $template): string
{
return (string)preg_replace('/{{--[\s\S]*?--}}/', '', $template);
return (string) preg_replace('/{{--[\s\S]*?--}}/', '', $template);
}

protected function replaceOpeningEcho(string $template, string $escape_callback_name): string
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function replaceOpeningTagWithBrackets(string $tag, string $template):
$regex = $this->getRegexForTagWithBrackets($tag);
$replacement = sprintf('<?php %s( $1 ): ?>', $tag);

return (string)preg_replace($regex, $replacement, $template);
return (string) preg_replace($regex, $replacement, $template);
}

protected function replaceClosingLoops(string $template): string
Expand Down Expand Up @@ -133,7 +133,7 @@ protected function replaceClosingPhp(string $template): string

protected function replaceUseDirective(string $template): string
{
return (string)preg_replace('/@use\s*\((["\'])(.*?)\1\)/s', '<?php use $2; ?>', $template);
return (string) preg_replace('/@use\s*\((["\'])(.*?)\1\)/s', '<?php use $2; ?>', $template);
}

protected function replaceSelectedDirective(string $template): string
Expand All @@ -142,7 +142,7 @@ protected function replaceSelectedDirective(string $template): string

$replacement = '<?php if ( $1 ) echo "selected=\"\""; ?>';

return (string)preg_replace($regex, $replacement, $template);
return (string) preg_replace($regex, $replacement, $template);
}

protected function replaceCheckedDirective(string $template): string
Expand All @@ -151,7 +151,7 @@ protected function replaceCheckedDirective(string $template): string

$replacement = '<?php if ( $1 ) echo "checked=\"\""; ?>';

return (string)preg_replace($regex, $replacement, $template);
return (string) preg_replace($regex, $replacement, $template);
}

protected function replaceSwitchDirectives(string $template): string
Expand All @@ -161,7 +161,7 @@ protected function replaceSwitchDirectives(string $template): string
// 1. remove space between @switch and the first "case",
// otherwise it'll case an error (spaces are threat as unexpected HTML).
$regex = '/@switch\s*\((.*)\)\s*<\?php/';
$template = (string)preg_replace($regex, '<?php switch($1): ?><?php', $template);
$template = (string) preg_replace($regex, '<?php switch($1): ?><?php', $template);

$template = str_replace('@break', '<?php break; ?>', $template);
$template = str_replace('@default', '<?php default: ?>', $template);
Expand All @@ -176,7 +176,7 @@ protected function replaceClassDirective(string $template, string $escape_callba
$regex = '/@class\s*\((\[.*])\)/s';
$replacement = $this->getCodeForConditionClasses($escape_callback_name);

return (string)preg_replace($regex, $replacement, $template);
return (string) preg_replace($regex, $replacement, $template);
}

protected function getCodeForConditionClasses(string $escape_callback_name): string
Expand Down
4 changes: 2 additions & 2 deletions private-classes/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function unregisterEventDetails(string $eventName, array $eventDetails):
*/
protected function getEventDetails(string $eventName): array
{
return true === key_exists($eventName, $this->eventDetails) ?
return key_exists($eventName, $this->eventDetails) ?
$this->eventDetails[$eventName] :
[];
}
Expand All @@ -93,7 +93,7 @@ protected function getEventDetails(string $eventName): array
*/
protected function getEventListeners(string $eventName): array
{
return true === key_exists($eventName, $this->eventListeners) ?
return key_exists($eventName, $this->eventListeners) ?
$this->eventListeners[$eventName] :
[];
}
Expand Down
4 changes: 2 additions & 2 deletions private-classes/Model/ModelFactoryWithDefaultsManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createModel(string $modelClass, ?Closure $setupModelCallback = n
{
$model = $this->modelFactory->createModel($modelClass);

if (true === ($model instanceof TemplateModelWithDefaultsInterface)) {
if ($model instanceof TemplateModelWithDefaultsInterface) {
$this->setDefaultValuesRecursively($model);
}

Expand Down Expand Up @@ -64,7 +64,7 @@ protected function setDefaultValuesRecursively(TemplateModelWithDefaultsInterfac
protected function getInnerModels(array $variables): array
{
return array_filter($variables, function ($item) {
return true === ($item instanceof TemplateModelWithDefaultsInterface) ;
return $item instanceof TemplateModelWithDefaultsInterface ;
});
}
}
2 changes: 1 addition & 1 deletion private-classes/Model/ModelNamespaceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(ObjectClassReader $objectClassReader)

public function resolveModelNamespace($modelOrClass): string
{
$modelNamespaceWithClassName = false === is_string($modelOrClass) ?
$modelNamespaceWithClassName = ! is_string($modelOrClass) ?
$this->objectClassReader->getObjectClass($modelOrClass) :
$modelOrClass;

Expand Down
2 changes: 1 addition & 1 deletion private-classes/Model/ModelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(

public function renderModel($modelOrClass, ?Closure $setupModelCallback = null): string
{
$model = true === is_string($modelOrClass) ?
$model = is_string($modelOrClass) ?
$this->viewFactory->createModel($modelOrClass) :
$modelOrClass;

Expand Down
2 changes: 1 addition & 1 deletion private-classes/Model/ModelRendererWithEventDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(

public function renderModel($modelOrClass, ?Closure $setupModelCallback = null): string
{
$modelClass = true === is_string($modelOrClass) ?
$modelClass = is_string($modelOrClass) ?
$modelOrClass :
get_class($modelOrClass);

Expand Down
4 changes: 2 additions & 2 deletions private-classes/Object/ObjectPropertyWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function assignPropertyValues(

array_map(
function (ReflectionProperty $reflectionProperty) use ($instance, $propertyValueProvider) {
if (true === $reflectionProperty->isInitialized($instance)) {
if ($reflectionProperty->isInitialized($instance)) {
return;
}

Expand Down Expand Up @@ -55,7 +55,7 @@ protected function setDefaultValueForSupportedType(
PropertyValueProviderInterface $propertyValueProvider,
ReflectionProperty $reflectionProperty
): bool {
if (false === $propertyValueProvider->supportsProperty($reflectionProperty)) {
if (! $propertyValueProvider->supportsProperty($reflectionProperty)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion private-classes/Object/ObjectReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getPropertyValues(object $instance, array $reflectionProperti
function (array $variableValues, ReflectionProperty $reflection_property) use ($instance) {
// make sure the property is initialized.
// Otherwise, we'll get "must not be accessed before initialization" error.
if (true === $reflection_property->isInitialized($instance)) {
if ($reflection_property->isInitialized($instance)) {
$variableValues[ $reflection_property->getName() ] = $reflection_property->getValue($instance);
}

Expand Down
8 changes: 4 additions & 4 deletions private-classes/Object/PropertyValueProviderByTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ public function __construct(PropertyValueProviderInterface $propertyValueProvide

public function supportsProperty(ReflectionProperty $property): bool
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return true;
}

$type = $this->getPropertyType($property);

return true === key_exists($type, $this->valuesByType);
return key_exists($type, $this->valuesByType);
}

public function getPropertyValue(ReflectionProperty $property)
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return $this->propertyValueProvider->getPropertyValue($property);
}

$type = $this->getPropertyType($property);

return true === key_exists($type, $this->valuesByType) ?
return key_exists($type, $this->valuesByType) ?
$this->valuesByType[$type] :
null;
}
Expand Down
8 changes: 4 additions & 4 deletions private-classes/Object/PropertyValueProviderForModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(

public function supportsProperty(ReflectionProperty $property): bool
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return true;
}

Expand All @@ -39,7 +39,7 @@ public function supportsProperty(ReflectionProperty $property): bool

public function getPropertyValue(ReflectionProperty $property)
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return $this->propertyValueProvider->getPropertyValue($property);
}

Expand All @@ -58,8 +58,8 @@ public function getPropertyValue(ReflectionProperty $property)
*/
protected function getValidModelClass(string $propertyType)
{
return true === class_exists($propertyType) &&
true === is_a($propertyType, TemplateModelInterface::class, true) ?
return class_exists($propertyType) &&
is_a($propertyType, TemplateModelInterface::class, true) ?
$propertyType :
null;
}
Expand Down
7 changes: 4 additions & 3 deletions private-classes/Object/PropertyValueProviderForNullable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ public function __construct(PropertyValueProviderInterface $propertyValueProvide

public function supportsProperty(ReflectionProperty $property): bool
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return true;
}

$type = $property->getType();

return null !== $type && true === $type->allowsNull();
return null !== $type &&
$type->allowsNull();
}

public function getPropertyValue(ReflectionProperty $property)
{
if (true === $this->propertyValueProvider->supportsProperty($property)) {
if ($this->propertyValueProvider->supportsProperty($property)) {
return $this->propertyValueProvider->getPropertyValue($property);
}

Expand Down
10 changes: 5 additions & 5 deletions private-classes/Template/FileModelTemplateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function resolveModelTemplate(TemplateModelInterface $model): string

$absoluteTemplatePath = $this->getAbsoluteTemplatePath($relativeTemplatePath);

return true === $this->isFileBasedTemplate ?
return $this->isFileBasedTemplate ?
$absoluteTemplatePath :
$this->getFileContent($absoluteTemplatePath);
}

protected function getFileContent(string $file): string
{
if (false === file_exists($file)) {
if (! file_exists($file)) {
return '';
}

Expand All @@ -75,13 +75,13 @@ protected function getAbsoluteTemplatePath(string $relativeTemplatePath): string
protected function getRelativeTemplatePath(string $relativeModelNamespace, string $modelName): string
{
$relativeModelPath = str_replace('\\', DIRECTORY_SEPARATOR, $relativeModelNamespace);
$modelName = (string)preg_replace('/([a-z])([A-Z])/', '$1-$2', $modelName);
$modelName = (string) preg_replace('/([a-z])([A-Z])/', '$1-$2', $modelName);

$relativeTemplatePath = $relativeModelPath;
$relativeTemplatePath .= '' !== $relativeTemplatePath ? DIRECTORY_SEPARATOR
: '';
$relativeTemplatePath .= $modelName;
$relativeTemplatePath .= strtolower($modelName);

return strtolower($relativeTemplatePath);
return $relativeTemplatePath;
}
}
2 changes: 1 addition & 1 deletion private-classes/Template/TemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function renderTemplate(string $template, array $variables = []): string

$this->codeExecutor->runCode($template, $variables);

return (string)ob_get_clean();
return (string) ob_get_clean();
}
}
10 changes: 5 additions & 5 deletions private-classes/Template/TemplateRendererWithCustomEscape.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ protected function setOutputEscapeCallback(
protected function caseToString($value): string
{
if (
true === is_string($value) ||
true === is_numeric($value)
is_string($value) ||
is_numeric($value)
) {
return (string)$value;
return (string) $value;
}

if (
true === is_object($value) &&
is_object($value) &&
method_exists($value, '__toString')
) {
return (string)$value;
return (string) $value;
}

return '';
Expand Down
4 changes: 2 additions & 2 deletions private-classes/Template/TemplateRendererWithFileTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function renderTemplate(string $template, array $variables = []): string

protected function getFileContent(string $file): string
{
if (false === file_exists($file)) {
if (! file_exists($file)) {
return '';
}

return (string)file_get_contents($file);
return (string) file_get_contents($file);
}
}
6 changes: 3 additions & 3 deletions private-classes/Template/TemplateRendererWithModelsRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function ($item) {
*/
protected function renderIfModel($item)
{
if (true === ( $item instanceof TemplateModelInterface )) {
if ($item instanceof TemplateModelInterface) {
$item = $this->modelRenderer->renderModel($item);
} elseif (
true === is_array($item) &&
false === is_callable($item)
is_array($item) &&
! is_callable($item)
) {
// @phpstan-ignore-next-line
$item = $this->renderModels($item);
Expand Down
2 changes: 1 addition & 1 deletion private-classes/View/ViewNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function __construct(
$modelRendererWithNamespace
);

if (true === $config->modelsAsStringsInTemplates()) {
if ($config->modelsAsStringsInTemplates()) {
$templateRenderer = $templateRendererWithModelsRender;
}

Expand Down
2 changes: 1 addition & 1 deletion src/View/ViewTemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(?ViewTemplateRendererConfig $config = null)
new TemplateRenderer($codeExecutor) :
$templateRenderer;

if (true === $config->fileBasedTemplates()) {
if ($config->fileBasedTemplates()) {
$templateRenderer = new TemplateRendererWithFileTemplate($templateRenderer);
}

Expand Down
Loading