diff --git a/code-quality/phpcs.xml b/code-quality/phpcs.xml
index 4f96f22..f24380a 100644
--- a/code-quality/phpcs.xml
+++ b/code-quality/phpcs.xml
@@ -4,6 +4,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/code-quality/phpstan.neon b/code-quality/phpstan.neon
index d2c9caf..bbf074a 100644
--- a/code-quality/phpstan.neon
+++ b/code-quality/phpstan.neon
@@ -2,4 +2,6 @@ parameters:
level: 9
paths:
- ../src
- - ../private-classes
\ No newline at end of file
+ - ../private-classes
+includes:
+ - vendor/phpstan/phpstan-strict-rules/rules.neon
\ No newline at end of file
diff --git a/private-classes/Blade/BladeCompiler.php b/private-classes/Blade/BladeCompiler.php
index 1ab56df..d76e1f3 100644
--- a/private-classes/Blade/BladeCompiler.php
+++ b/private-classes/Blade/BladeCompiler.php
@@ -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
@@ -100,7 +100,7 @@ protected function replaceOpeningTagWithBrackets(string $tag, string $template):
$regex = $this->getRegexForTagWithBrackets($tag);
$replacement = sprintf('', $tag);
- return (string)preg_replace($regex, $replacement, $template);
+ return (string) preg_replace($regex, $replacement, $template);
}
protected function replaceClosingLoops(string $template): string
@@ -133,7 +133,7 @@ protected function replaceClosingPhp(string $template): string
protected function replaceUseDirective(string $template): string
{
- return (string)preg_replace('/@use\s*\((["\'])(.*?)\1\)/s', '', $template);
+ return (string) preg_replace('/@use\s*\((["\'])(.*?)\1\)/s', '', $template);
}
protected function replaceSelectedDirective(string $template): string
@@ -142,7 +142,7 @@ protected function replaceSelectedDirective(string $template): string
$replacement = '';
- return (string)preg_replace($regex, $replacement, $template);
+ return (string) preg_replace($regex, $replacement, $template);
}
protected function replaceCheckedDirective(string $template): string
@@ -151,7 +151,7 @@ protected function replaceCheckedDirective(string $template): string
$replacement = '';
- return (string)preg_replace($regex, $replacement, $template);
+ return (string) preg_replace($regex, $replacement, $template);
}
protected function replaceSwitchDirectives(string $template): string
@@ -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, '', $template);
$template = str_replace('@default', '', $template);
@@ -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
diff --git a/private-classes/EventDispatcher.php b/private-classes/EventDispatcher.php
index 4c78b38..58f2db0 100644
--- a/private-classes/EventDispatcher.php
+++ b/private-classes/EventDispatcher.php
@@ -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] :
[];
}
@@ -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] :
[];
}
diff --git a/private-classes/Model/ModelFactoryWithDefaultsManagement.php b/private-classes/Model/ModelFactoryWithDefaultsManagement.php
index 5d337ee..fd83994 100644
--- a/private-classes/Model/ModelFactoryWithDefaultsManagement.php
+++ b/private-classes/Model/ModelFactoryWithDefaultsManagement.php
@@ -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);
}
@@ -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 ;
});
}
}
diff --git a/private-classes/Model/ModelNamespaceResolver.php b/private-classes/Model/ModelNamespaceResolver.php
index 0ecdfea..c61a016 100644
--- a/private-classes/Model/ModelNamespaceResolver.php
+++ b/private-classes/Model/ModelNamespaceResolver.php
@@ -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;
diff --git a/private-classes/Model/ModelRenderer.php b/private-classes/Model/ModelRenderer.php
index 12af6e0..e31c61c 100644
--- a/private-classes/Model/ModelRenderer.php
+++ b/private-classes/Model/ModelRenderer.php
@@ -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;
diff --git a/private-classes/Model/ModelRendererWithEventDetails.php b/private-classes/Model/ModelRendererWithEventDetails.php
index 1af9c31..81d374b 100644
--- a/private-classes/Model/ModelRendererWithEventDetails.php
+++ b/private-classes/Model/ModelRendererWithEventDetails.php
@@ -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);
diff --git a/private-classes/Object/ObjectPropertyWriter.php b/private-classes/Object/ObjectPropertyWriter.php
index 8d003e8..9d189de 100644
--- a/private-classes/Object/ObjectPropertyWriter.php
+++ b/private-classes/Object/ObjectPropertyWriter.php
@@ -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;
}
@@ -55,7 +55,7 @@ protected function setDefaultValueForSupportedType(
PropertyValueProviderInterface $propertyValueProvider,
ReflectionProperty $reflectionProperty
): bool {
- if (false === $propertyValueProvider->supportsProperty($reflectionProperty)) {
+ if (! $propertyValueProvider->supportsProperty($reflectionProperty)) {
return false;
}
diff --git a/private-classes/Object/ObjectReader.php b/private-classes/Object/ObjectReader.php
index 5e35bac..4a638e8 100644
--- a/private-classes/Object/ObjectReader.php
+++ b/private-classes/Object/ObjectReader.php
@@ -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);
}
diff --git a/private-classes/Object/PropertyValueProviderByTypes.php b/private-classes/Object/PropertyValueProviderByTypes.php
index 8398004..c4d3f54 100644
--- a/private-classes/Object/PropertyValueProviderByTypes.php
+++ b/private-classes/Object/PropertyValueProviderByTypes.php
@@ -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;
}
diff --git a/private-classes/Object/PropertyValueProviderForModels.php b/private-classes/Object/PropertyValueProviderForModels.php
index b63a1e0..734efb5 100644
--- a/private-classes/Object/PropertyValueProviderForModels.php
+++ b/private-classes/Object/PropertyValueProviderForModels.php
@@ -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;
}
@@ -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);
}
@@ -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;
}
diff --git a/private-classes/Object/PropertyValueProviderForNullable.php b/private-classes/Object/PropertyValueProviderForNullable.php
index f3cd0aa..29c4b89 100644
--- a/private-classes/Object/PropertyValueProviderForNullable.php
+++ b/private-classes/Object/PropertyValueProviderForNullable.php
@@ -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);
}
diff --git a/private-classes/Template/FileModelTemplateResolver.php b/private-classes/Template/FileModelTemplateResolver.php
index f0bc621..d83aea6 100644
--- a/private-classes/Template/FileModelTemplateResolver.php
+++ b/private-classes/Template/FileModelTemplateResolver.php
@@ -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 '';
}
@@ -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;
}
}
diff --git a/private-classes/Template/TemplateRenderer.php b/private-classes/Template/TemplateRenderer.php
index d1b2627..3678ada 100644
--- a/private-classes/Template/TemplateRenderer.php
+++ b/private-classes/Template/TemplateRenderer.php
@@ -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();
}
}
diff --git a/private-classes/Template/TemplateRendererWithCustomEscape.php b/private-classes/Template/TemplateRendererWithCustomEscape.php
index 8c50f0e..d78c25d 100644
--- a/private-classes/Template/TemplateRendererWithCustomEscape.php
+++ b/private-classes/Template/TemplateRendererWithCustomEscape.php
@@ -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 '';
diff --git a/private-classes/Template/TemplateRendererWithFileTemplate.php b/private-classes/Template/TemplateRendererWithFileTemplate.php
index 8d70e43..730ada2 100644
--- a/private-classes/Template/TemplateRendererWithFileTemplate.php
+++ b/private-classes/Template/TemplateRendererWithFileTemplate.php
@@ -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);
}
}
diff --git a/private-classes/Template/TemplateRendererWithModelsRender.php b/private-classes/Template/TemplateRendererWithModelsRender.php
index b18c0b1..7c72768 100644
--- a/private-classes/Template/TemplateRendererWithModelsRender.php
+++ b/private-classes/Template/TemplateRendererWithModelsRender.php
@@ -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);
diff --git a/private-classes/View/ViewNamespace.php b/private-classes/View/ViewNamespace.php
index 69f98a9..dd8d33b 100644
--- a/private-classes/View/ViewNamespace.php
+++ b/private-classes/View/ViewNamespace.php
@@ -117,7 +117,7 @@ public function __construct(
$modelRendererWithNamespace
);
- if (true === $config->modelsAsStringsInTemplates()) {
+ if ($config->modelsAsStringsInTemplates()) {
$templateRenderer = $templateRendererWithModelsRender;
}
diff --git a/src/View/ViewTemplateRenderer.php b/src/View/ViewTemplateRenderer.php
index 454f138..34ed19b 100644
--- a/src/View/ViewTemplateRenderer.php
+++ b/src/View/ViewTemplateRenderer.php
@@ -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);
}
diff --git a/src/ViewsManager.php b/src/ViewsManager.php
index ab29ae2..cf640e1 100644
--- a/src/ViewsManager.php
+++ b/src/ViewsManager.php
@@ -63,7 +63,7 @@ public function registerNamespace(string $namespace, ViewNamespaceConfig $config
public function createModel(string $modelClass, ?Closure $setupModelCallback = null)
{
- if (false === $this->isModel($modelClass)) {
+ if (! $this->isModel($modelClass)) {
throw $this->makeWrongModelException($modelClass);
}
@@ -85,7 +85,7 @@ public function createModel(string $modelClass, ?Closure $setupModelCallback = n
public function renderModel($modelOrClass, ?Closure $setupModelCallback = null): string
{
- if (false === $this->isModel($modelOrClass)) {
+ if (! $this->isModel($modelOrClass)) {
throw $this->makeWrongModelException($modelOrClass);
}
@@ -121,7 +121,7 @@ protected function makeNamespaceNotResolvedException(string $namespace): Excepti
*/
protected function makeWrongModelException($modelOrClass): Exception
{
- $modelClass = true === is_object($modelOrClass) ?
+ $modelClass = is_object($modelOrClass) ?
get_class($modelOrClass) :
$modelOrClass;
@@ -135,16 +135,16 @@ protected function makeWrongModelException($modelOrClass): Exception
*/
protected function isModel($modelOrClass): bool
{
- if (true === is_object($modelOrClass)) {
+ if (is_object($modelOrClass)) {
return $modelOrClass instanceof TemplateModelInterface;
}
- if (false === class_exists($modelOrClass)) {
+ if (! class_exists($modelOrClass)) {
return false;
}
$implementedList = class_implements($modelOrClass);
- return true === in_array(TemplateModelInterface::class, $implementedList, true);
+ return in_array(TemplateModelInterface::class, $implementedList, true);
}
}
diff --git a/tests/pest/Unit/Template/FileModelTemplateProviderTest.php b/tests/pest/Unit/Template/FileModelTemplateProviderTest.php
index 7c14f99..94c4193 100644
--- a/tests/pest/Unit/Template/FileModelTemplateProviderTest.php
+++ b/tests/pest/Unit/Template/FileModelTemplateProviderTest.php
@@ -227,7 +227,7 @@ public function testGetFileBasedTemplateHandlesCamelCaseConversion(): void
public function testGetTemplateHandlesNestedNamespaces(): void
{
// given
- vfsStream::setup('templates', null, ['admin/dashboard-view.blade.php' => 'Dashboard Content']);
+ vfsStream::setup('templates', null, ['Admin/dashboard-view.blade.php' => 'Dashboard Content']);
$templateModel = Mockery::mock(TemplateModelInterface::class);
$modelNamespaceProviderMock = Mockery::mock(ModelNamespaceResolverInterface::class);
$modelNameProviderMock = Mockery::mock(ModelNameResolverInterface::class);
@@ -287,7 +287,7 @@ public function testGetFileBasedTemplateHandlesNestedNamespaces(): void
->with($templateModel)
->andReturn('DashboardView');
- $this->assertSame(vfsStream::url('templates/admin/dashboard-view.blade.php'), $result());
+ $this->assertSame(vfsStream::url('templates/Admin/dashboard-view.blade.php'), $result());
// apply
Mockery::close();
diff --git a/tests/templates/inline/use-double-quote.blade.php b/tests/templates/inline/use-double-quote.blade.php
index 2b8e508..e1f822f 100644
--- a/tests/templates/inline/use-double-quote.blade.php
+++ b/tests/templates/inline/use-double-quote.blade.php
@@ -1 +1,2 @@
-@use("my\package")
\ No newline at end of file
+@use("my\package")
+@use("function my\package\feature")
\ No newline at end of file
diff --git a/tests/templates/inline/use-double-quote.php b/tests/templates/inline/use-double-quote.php
index a3aea8a..6a88330 100644
--- a/tests/templates/inline/use-double-quote.php
+++ b/tests/templates/inline/use-double-quote.php
@@ -1 +1,2 @@
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/tests/templates/inline/use-single-quote.blade.php b/tests/templates/inline/use-single-quote.blade.php
index 715f460..ab5cc26 100644
--- a/tests/templates/inline/use-single-quote.blade.php
+++ b/tests/templates/inline/use-single-quote.blade.php
@@ -1 +1,2 @@
-@use('my\package')
\ No newline at end of file
+@use('my\package')
+@use('function my\package\feature')
\ No newline at end of file
diff --git a/tests/templates/inline/use-single-quote.php b/tests/templates/inline/use-single-quote.php
index a3aea8a..6a88330 100644
--- a/tests/templates/inline/use-single-quote.php
+++ b/tests/templates/inline/use-single-quote.php
@@ -1 +1,2 @@
-
\ No newline at end of file
+
+
\ No newline at end of file