Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 23, 2023
1 parent 217bb42 commit eb38094
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
2 changes: 1 addition & 1 deletion plugins/manager/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
}

try {
rex_sql::factory()->setQuery('UPDATE ' . rex_yform_manager_field::table() . ' SET `format` = "" WHERE type_name = "datestamp" AND `format` = "mysql"');
rex_sql::factory()->setQuery('UPDATE ' . rex::getTable('yform_field') . ' SET `format` = "" WHERE type_name = "datestamp" AND `format` = "mysql"');
} catch (rex_sql_exception $e) {
}

Expand Down
53 changes: 18 additions & 35 deletions plugins/manager/lib/yform/manager/dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class rex_yform_manager_dataset
/** @var bool */
private $historyEnabled = true;

final private function __construct(string $table, ?int $id = null)
final private function __construct(string $table, int $id = null)
{
$this->table = $table;
$this->id = $id;
Expand All @@ -46,7 +46,7 @@ final private function __construct(string $table, ?int $id = null)
/**
* @return static
*/
public static function create(?string $table = null): self
public static function create(string $table = null): self
{
$table = $table ?: static::modelToTable();
/** @var class-string<static> $class */
Expand All @@ -59,10 +59,7 @@ public static function create(?string $table = null): self
return $dataset;
}

/**
* @return null|static
*/
public static function get(int $id, ?string $table = null): ?self
public static function get(int $id, string $table = null): ?self
{
if ($id <= 0) {
throw new InvalidArgumentException(sprintf('$id has to be an integer greater than 0, but "%s" given', $id));
Expand All @@ -76,16 +73,16 @@ public static function get(int $id, ?string $table = null): ?self
return $class::get($id, $table);
}

/* @phpstan-ignore-next-line */
return static::getInstance([$table, $id], static function ($table, $id) {
return static::query($table)->findId($id);
});
}

/**
* @throws rex_exception if dataset does not exist
* @return static
*/
public static function require(int $id, ?string $table = null): self
public static function require(int $id, string $table = null): self
{
$dataset = self::get($id, $table);

Expand All @@ -99,9 +96,9 @@ public static function require(int $id, ?string $table = null): self
}

/**
* @return static
* @return static|rex_yform_manager_dataset
*/
public static function getRaw(int $id, ?string $table = null): self
public static function getRaw(int $id, string $table = null): self
{
if ($id <= 0) {
throw new InvalidArgumentException(sprintf('$id has to be an integer greater than 0, but "%s" given', $id));
Expand All @@ -115,21 +112,17 @@ public static function getRaw(int $id, ?string $table = null): self
return $class::getRaw($id, $table);
}

$callback = static function ($table, $id) {
/* @phpstan-ignore-next-line */
return static::getInstance([$table, $id], static function ($table, $id) {
$class = self::tableToModel($table);
return new $class($table, $id);
};
// needed for php 5
$callback = $callback->bindTo(null, __CLASS__);

/** @var static */
return static::getInstance([$table, $id], $callback);
});
}

/**
* @return rex_yform_manager_collection<static>
*/
public static function getAll(?string $table = null): rex_yform_manager_collection
public static function getAll(string $table = null): rex_yform_manager_collection
{
return static::query($table)->find();
}
Expand All @@ -148,15 +141,15 @@ public static function table(): rex_yform_manager_table
/**
* @return rex_yform_manager_query<static>
*/
public static function query(?string $table = null): rex_yform_manager_query
public static function query(string $table = null): rex_yform_manager_query
{
return rex_yform_manager_query::get($table ?: static::modelToTable());
}

/**
* @return null|static
* @return null|static|rex_yform_manager_dataset
*/
public static function queryOne(string $query, array $params = [], ?string $table = null): ?self
public static function queryOne(string $query, array $params = [], string $table = null): ?self
{
$table = $table ?: static::modelToTable();

Expand Down Expand Up @@ -184,9 +177,9 @@ public static function queryOne(string $query, array $params = [], ?string $tabl
}

/**
* @return rex_yform_manager_collection<static>
* @return rex_yform_manager_collection<static>|rex_yform_manager_collection<rex_yform_manager_dataset>
*/
public static function queryCollection(string $query, array $params = [], ?string $table = null): rex_yform_manager_collection
public static function queryCollection(string $query, array $params = [], string $table = null): rex_yform_manager_collection
{
$table = $table ?: static::modelToTable();

Expand Down Expand Up @@ -264,7 +257,6 @@ public function hasValue(string $key): bool
}

/**
* @param mixed $value
* @return $this
*/
public function setValue(string $key, $value): self
Expand All @@ -279,9 +271,6 @@ public function setValue(string $key, $value): self
return $this;
}

/**
* @return mixed
*/
public function getValue(string $key)
{
if ('id' === $key) {
Expand Down Expand Up @@ -507,7 +496,7 @@ public function getForm(): rex_yform
/**
* @param null|callable(rex_yform):void $afterFieldsExecuted
*/
public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string
public function executeForm(rex_yform $yform, callable $afterFieldsExecuted = null): string
{
$exists = $this->exists();
$oldData = $this->getData();
Expand Down Expand Up @@ -660,17 +649,11 @@ public function __isset(string $key): bool
return $this->hasValue($key);
}

/**
* @return mixed
*/
public function __get(string $key)
{
return $this->getValue($key);
}

/**
* @param mixed $value
*/
public function __set(string $key, $value): void
{
$this->setValue($key, $value);
Expand Down Expand Up @@ -765,7 +748,7 @@ final protected static function modelToTable(): string
/**
* @return static
*/
private static function fromSqlData(array $data, string $table): self
final protected static function fromSqlData(array $data, string $table): self
{
$id = (int) $data['id'];
$class = self::tableToModel($table);
Expand Down
4 changes: 2 additions & 2 deletions plugins/manager/lib/yform/manager/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

class rex_yform_manager_table implements ArrayAccess
final class rex_yform_manager_table implements ArrayAccess
{
public static array $tableLayouts = [];
public static string $defaultTableLayout = 'yform/manager/page/layout.php';
Expand Down Expand Up @@ -71,7 +71,7 @@ public static function get($tableName)
return null;
}

return self::$tables[$tableName] = new static($cache[$tableName]);
return self::$tables[$tableName] = new self($cache[$tableName]);
}

public static function require(string $tableName): self
Expand Down

0 comments on commit eb38094

Please sign in to comment.