Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc #4

Merged
merged 1 commit into from
Feb 18, 2024
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
2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

return ECSConfig::configure()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withPreparedSets(psr12: true);
->withPreparedSets(psr12: true, common: true);
36 changes: 18 additions & 18 deletions src/CakePHP/PortedInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ final class PortedInflector
*
* @var array<string, mixed[]>
*/
protected static $_plural = array(
'rules' => array(
private static $_plural = [
'rules' => [
'/(s)tatus$/i' => '\1tatuses',
'/(quiz)$/i' => '\1zes',
'/^(ox)$/i' => '\1\2en',
Expand All @@ -38,8 +38,8 @@ final class PortedInflector
'/s$/' => 's',
'/^$/' => '',
'/$/' => 's',
),
'uninflected' => array(
],
'uninflected' => [
'.*[nrlm]ese',
'.*data',
'.*deer',
Expand All @@ -50,9 +50,9 @@ final class PortedInflector
'.*sheep',
'people',
'feedback',
'stadia'
),
'irregular' => array(
'stadia',
],
'irregular' => [
'atlas' => 'atlases',
'beef' => 'beefs',
'brief' => 'briefs',
Expand Down Expand Up @@ -92,16 +92,16 @@ final class PortedInflector
'tooth' => 'teeth',
'goose' => 'geese',
'foot' => 'feet',
'sieve' => 'sieves'
)
);
'sieve' => 'sieves',
],
];

/**
* Words that should not be inflected
*
* @var array
*/
protected static $_uninflected = array(
private static $_uninflected = [
'Amoyese',
'bison',
'Borghese',
Expand Down Expand Up @@ -181,15 +181,15 @@ final class PortedInflector
'Wenchowese',
'whiting',
'wildebeest',
'Yengeese'
);
'Yengeese',
];

/**
* Method cache array.
*
* @var array
*/
protected static $_cache = array();
private static $_cache = [];

/**
* Returns corresponding table name for given model $className. ("people" for the model class "Person").
Expand All @@ -200,7 +200,7 @@ final class PortedInflector
*/
public static function tableize($className)
{
return PortedInflector::pluralize(PortedInflector::underscore($className));
return self::pluralize(self::underscore($className));
}

/**
Expand All @@ -216,18 +216,18 @@ public static function pluralize($word)
return static::$_cache['pluralize'][$word];
}

if (!isset(static::$_plural['merged']['irregular'])) {
if (! isset(static::$_plural['merged']['irregular'])) {
static::$_plural['merged']['irregular'] = static::$_plural['irregular'];
}

if (!isset(static::$_plural['merged']['uninflected'])) {
if (! isset(static::$_plural['merged']['uninflected'])) {
static::$_plural['merged']['uninflected'] = array_merge(
static::$_plural['uninflected'],
static::$_uninflected
);
}

if (!isset(static::$_plural['cacheUninflected']) || !isset(static::$_plural['cacheIrregular'])) {
if (! isset(static::$_plural['cacheUninflected']) || ! isset(static::$_plural['cacheIrregular'])) {
static::$_plural['cacheUninflected'] = '(?:' . implode(
'|',
static::$_plural['merged']['uninflected']
Expand Down
2 changes: 1 addition & 1 deletion src/ClassMethodExtension/ModelMethodExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static function (
return $methodReflection->getName() === $methodName;
}
);
if (!$methodReflections) {
if (! $methodReflections) {
throw new Exception('Method not found');
}
return reset($methodReflections);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(ReflectionProvider $reflectionProvider)

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
if (!array_filter($this->getContainingClassNames(), [$classReflection, 'is'])) {
if (! array_filter($this->getContainingClassNames(), [$classReflection, 'is'])) {
return false;
}

Expand All @@ -37,7 +37,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
static fn (string $componentName): bool => $componentName === $propertyName
);

if (!$isDefinedInComponentsProperty) {
if (! $isDefinedInComponentsProperty) {
return false;
}

Expand Down Expand Up @@ -80,15 +80,15 @@ private function getDefinedComponentsAsList(ClassReflection $classReflection): a
$definedComponents = [];

foreach (array_merge([$classReflection], $classReflection->getParents()) as $class) {
if (!$class->hasProperty('components')) {
if (! $class->hasProperty('components')) {
continue;
}

$defaultValue = $class->getNativeProperty('components')
->getNativeReflection()
->getDefaultValueExpression();

if (!$defaultValue instanceof Array_) {
if (! $defaultValue instanceof Array_) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ModelBehaviorMethodExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function filterBehaviorMethods(
ExtendedMethodReflection $methodReflection
): bool {
return $methodReflection->isPublic()
&& !$methodReflection->isStatic()
&& ! $methodReflection->isStatic()
&& array_filter(
$methodReflection->getVariants(),
[$this, 'filterBehaviorMethodVariants']
Expand All @@ -87,7 +87,7 @@ private function filterBehaviorMethodVariants(
/** @var ParameterReflection|null $firstParameter */
$firstParameter = array_shift($parameters);

if (!$firstParameter) {
if (! $firstParameter) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ClassReflectionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function getClassNamesFromPaths(
$classPaths = [];
foreach ($paths as $path) {
$filePaths = glob($path);
if (!is_array($filePaths)) {
if (! is_array($filePaths)) {
throw new Exception(sprintf('glob(%s) caused an error', $path));
}
$classPaths = array_merge($classPaths, $filePaths);
Expand Down
2 changes: 1 addition & 1 deletion src/ReturnTypeExtension/ClassRegistryInitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
{
$argumentType = $scope->getType($methodCall->getArgs()[0]->value);

if (!$argumentType instanceof ConstantStringType) {
if (! $argumentType instanceof ConstantStringType) {
return $this->getDefaultType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
{
$arg = $methodCall->getArgs()[0]->value;

if (!$arg instanceof String_) {
if (! $arg instanceof String_) {
return null;
}

$componentName = $arg->value . 'Component';

if (!$this->reflectionProvider->hasClass($componentName)) {
if (! $this->reflectionProvider->hasClass($componentName)) {
return null;
}

if (!$this->reflectionProvider->getClass($componentName)->is('Component')) {
if (! $this->reflectionProvider->getClass($componentName)->is('Component')) {
return null;
}

Expand Down
1 change: 0 additions & 1 deletion src/Service/SchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ final class SchemaService
private ?array $tableSchemas = null;

/**
* @param ReflectionProvider $reflectionProvider
* @param array<string> $schemaPaths
*/
public function __construct(
Expand Down
30 changes: 20 additions & 10 deletions tests/Source/Config/Schema/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,38 @@ class AppSchema extends CakeSchema
/**
* @var array<string, mixed>
*/
public $basic_models = array(
'id' => array(
public $basic_models = [
'id' => [
'type' => 'integer',
'null' => false,
'default' => null,
'length' => 10,
'key' => 'primary',
),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
);
],
'indexes' => [
'PRIMARY' => [
'column' => 'id',
'unique' => 1,
],
],
];

/**
* @var array<string, mixed>
*/
public $table_without_models = array(
'id' => array(
public $table_without_models = [
'id' => [
'type' => 'integer',
'null' => false,
'default' => null,
'length' => 10,
'key' => 'primary',
),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
);
],
'indexes' => [
'PRIMARY' => [
'column' => 'id',
'unique' => 1,
],
],
];
}
Loading