Skip to content
Snippets Groups Projects
Commit 5e2b6e03 authored by Jan Kuchař's avatar Jan Kuchař
Browse files

Merge branch 'readonly-class' into 'master'

add readonlyClass capability

See merge request !59
parents ea5bb6e5 06a57745
No related branches found
No related tags found
1 merge request!59add readonlyClass capability
Pipeline #49515 passed
<?php
declare(strict_types=1);
namespace Grifart\ClassScaffolder\Capabilities;
use Grifart\ClassScaffolder\ClassInNamespace;
use Grifart\ClassScaffolder\Definition\ClassDefinition;
final class ReadonlyClass implements Capability
{
public function applyTo(
ClassDefinition $definition,
ClassInNamespace $draft,
?ClassInNamespace $current,
): void
{
$classType = $draft->getClassType();
$classType->setReadOnly();
CapabilityTools::checkIfAllFieldsArePresent($definition, $classType);
foreach ($definition->getFields() as $field) {
$fieldName = $field->getName();
$property = CapabilityTools::getProperty($classType, $fieldName);
$property->setPublic();
}
}
}
...@@ -54,6 +54,10 @@ function properties(): Properties { ...@@ -54,6 +54,10 @@ function properties(): Properties {
return new Properties(); return new Properties();
} }
function readonlyClass(): ReadonlyClass {
return new ReadonlyClass();
}
function readonlyProperties(): ReadonlyProperties { function readonlyProperties(): ReadonlyProperties {
return new ReadonlyProperties(); return new ReadonlyProperties();
} }
......
<?php
/**
* Do not edit. This is generated file. Modify definition file instead.
*/
declare(strict_types=1);
namespace RootNamespace\SubNamespace;
use Iterator;
final readonly class ClassName
{
/**
* @param Iterator<string, int[]> $field2
*/
public function __construct(
public ?string $field1,
public Iterator $field2,
) {
}
}
<?php
declare(strict_types=1);
namespace Grifart\ClassScaffolder\Test\Capabilities;
use function Grifart\ClassScaffolder\Capabilities\constructorWithPromotedProperties;
use function Grifart\ClassScaffolder\Capabilities\readonlyClass;
require __DIR__ . '/../bootstrap.php';
final class ReadonlyClassTest extends CapabilityTestCase
{
protected function getCapabilities(): array
{
return [
constructorWithPromotedProperties(),
readonlyClass(),
];
}
}
(new ReadonlyClassTest())->run();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment