Skip to content

Commit

Permalink
General Code Update
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Feb 3, 2025
1 parent 4367ec4 commit 91a5464
Show file tree
Hide file tree
Showing 791 changed files with 5,635 additions and 6,522 deletions.
4 changes: 3 additions & 1 deletion components/ILIAS/ActiveRecord/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

namespace ILIAS;

class ActiveRecord implements Component\Component
use ILIAS\Component\Component;

class ActiveRecord implements Component
{
public function init(
array | \ArrayAccess &$define,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function printStats(): void
* @param $id
* @throws arException
*/
public static function get($class, $id): \ActiveRecord
public static function get(string $class, string $id): \ActiveRecord
{
new $class();
if (!self::isCached($class, $id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getSaveTableName(arStatement $arStatement): string
return $tableName;
}

#[\Override]
public function add(arStatement $arStatement): void
{
$arStatement->setTableNameAs($this->getSaveTableName($arStatement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function asSQLStatement(): string
$return = 'SELECT ';
if ($this->hasStatements()) {
$activeRecord = $this->getAr();
$selectSQLs = array_map(fn ($select) => $select->asSQLStatement($activeRecord), $this->getSelects());
$selectSQLs = array_map(fn($select): string => $select->asSQLStatement($activeRecord), $this->getSelects());
$return .= implode(', ', $selectSQLs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,18 @@ public function read(ActiveRecord $activeRecord): array
if ($this->cache_container->has($key)) {
$cached_value = $this->cache_container->get(
$key,
new Transformation(function ($value): ?array {
return is_array($value) ? $value : null;
})
new Transformation(fn($value): ?array => is_array($value) ? $value : null)
);
if (is_array($cached_value)) {
return array_map(function ($result): \stdClass {
return (object) $result;
}, $cached_value);
return array_map(fn($result): \stdClass => (object) $result, $cached_value);
}
}

$results = $this->arConnector->read($activeRecord);

$this->cache_container->set(
$key,
array_map(function ($result): array {
return (array) $result;
}, $results)
array_map(fn($result): array => (array) $result, $results)
);

return $results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ protected function assignMessageToCode(): void

public function __toString(): string
{
return implode('<br>', [$this::class, $this->message]);
return implode('<br>', [static::class, $this->message]);
}
}
1 change: 1 addition & 0 deletions components/ILIAS/ActiveRecord/Fields/class.arField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
class arField
{
public $not_null;
protected bool $is_unique = false;
public const FIELD_TYPE_TEXT = 'text'; // MySQL varchar, char
public const FIELD_TYPE_INTEGER = 'integer'; // MySQL tinyint, smallint, mediumint, int, bigint
Expand Down
6 changes: 1 addition & 5 deletions components/ILIAS/ActiveRecord/Fields/class.arFieldList.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public function __construct(protected ActiveRecord $activeRecord)

public static function mapKey(string $key): string
{
if (isset(self::$key_maps[$key])) {
return self::$key_maps[$key];
}

return $key;
return self::$key_maps[$key] ?? $key;
}

/**
Expand Down
25 changes: 13 additions & 12 deletions components/ILIAS/ActiveRecord/class.ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function asArray(): array

public function buildFromArray(array $array): static
{
$class = $this::class;
$class = static::class;
$primary = $this->getArFieldList()->getPrimaryFieldName();
$primary_value = $array[$primary];
if ($primary_value && arObjectCache::isCached($class, $primary_value)) {
Expand All @@ -165,7 +165,7 @@ public function buildFromArray(array $array): static
* @return string|mixed
* @noinspection NullPointerExceptionInspection
*/
public function fixDateField($field_name, $value)
public function fixDateField($field_name, string $value)
{
if ($this->getArFieldList()->getFieldByName($field_name)->isDateField()) {
return $this->getArConnector()->fixDate($value);
Expand Down Expand Up @@ -521,7 +521,7 @@ public static function where($where, $operator = null): \ActiveRecordList
public static function innerjoinAR(
ActiveRecord $activeRecord,
$on_this,
$on_external,
string $on_external,
array $fields = ['*'],
string $operator = '=',
bool $both_external = false
Expand All @@ -543,9 +543,9 @@ public static function innerjoinAR(
* @return $this
*/
public static function innerjoin(
$tablename,
string $tablename,
$on_this,
$on_external,
string $on_external,
array $fields = ['*'],
string $operator = '=',
bool $both_external = false
Expand All @@ -562,9 +562,9 @@ public static function innerjoin(
* @return $this
*/
public static function leftjoin(
$tablename,
string $tablename,
$on_this,
$on_external,
string $on_external,
array $fields = ['*'],
string $operator = '=',
bool $both_external = false
Expand Down Expand Up @@ -682,7 +682,7 @@ public static function raw(bool $set_raw = true): \ActiveRecordList
* @param null $values
* @return mixed[]|mixed[][]|int[]|string[]|null[]
*/
public static function getArray(?string $key = null, $values = null): array
public static function getArray(?string $key = null, string|array|null $values = null): array
{
$activeRecordList = new ActiveRecordList(self::getCalledClass());

Expand All @@ -701,19 +701,20 @@ public static function getArray(?string $key = null, $values = null): array
public function __call($name, $arguments)
{
// Getter
if (preg_match("/get([a-zA-Z]*)/u", $name, $matches) && (is_countable($arguments) ? count(
if (preg_match("/get([a-zA-Z]*)/u", (string) $name, $matches) && (is_countable($arguments) ? count(
$arguments
) : 0) === 0) {
return $this->{self::fromCamelCase($matches[1])};
}
// Setter
if (!preg_match("/set([a-zA-Z]*)/u", $name, $matches)) {
return;
if (!preg_match("/set([a-zA-Z]*)/u", (string) $name, $matches)) {
return null;
}
if (count($arguments) !== 1) {
return;
return null;
}
$this->{self::fromCamelCase($matches[1])} = $arguments[0];
return null;
}

public static function _toCamelCase(string $str, bool $capitalise_first_char = false): ?string
Expand Down
6 changes: 3 additions & 3 deletions components/ILIAS/ActiveRecord/class.ActiveRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function limit(int $start, int $end): self
public function innerjoinAR(
ActiveRecord $activeRecord,
$on_this,
$on_external,
string $on_external,
array $fields = ['*'],
string $operator = '=',
bool $both_external = false
Expand Down Expand Up @@ -497,8 +497,8 @@ protected function load(): void
$arField = $obj->getArFieldList()->getFieldByName($key);
if ($arField !== null && ($arField->isDateField() && $this->getDateFormat())) {
$res_awake[$key . '_unformatted'] = $value;
$res_awake[$key . '_unix'] = strtotime($value);
$value = date($this->getDateFormat(), strtotime($value));
$res_awake[$key . '_unix'] = strtotime((string) $value);
$value = date($this->getDateFormat(), strtotime((string) $value));
}
$waked = $this->getAR()->wakeUp($key, $value);
$res_awake[$key] = $waked ?? $value;
Expand Down
4 changes: 4 additions & 0 deletions components/ILIAS/ActiveRecord/class.CachedActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,28 @@ private function buildHash(): string
return md5(serialize($hashing));
}

#[\Override]
public function create(): void
{
parent::create();
}

#[\Override]
public function read(): void
{
parent::read();
$this->_hash = $this->buildHash();
}

#[\Override]
public function update(): void
{
if ($this->buildHash() !== $this->_hash) {
parent::update();
}
}

#[\Override]
public function delete(): void
{
parent::delete(); // TODO: Change the autogenerated stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@

declare(strict_types=1);

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ILIAS\DI\Container;

class ilServicesActiveRecordConnectorTest extends TestCase
{
private ?\ILIAS\DI\Container $dic_backup = null;
private ?Container $dic_backup = null;
/**
* @var ilDBInterface|\PHPUnit\Framework\MockObject\MockObject
* @var ilDBInterface|MockObject
*/
protected $db_mock;
protected ?MockObject $db_mock = null;

protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@

declare(strict_types=1);

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ILIAS\DI\Container;

class ilServicesActiveRecordFieldTest extends TestCase
{
private ?\ILIAS\DI\Container $dic_backup = null;
private ?Container $dic_backup = null;
/**
* @var ilDBInterface|\PHPUnit\Framework\MockObject\MockObject
* @var ilDBInterface|MockObject
*/
protected $db_mock;
protected ?MockObject $db_mock = null;

protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

namespace ILIAS;

class AdministrativeNotification implements Component\Component
use ILIAS\Component\Component;
use ILIAS\Setup\Agent;
use ILIAS\Refinery\Factory;

class AdministrativeNotification implements Component
{
public function init(
array | \ArrayAccess &$define,
Expand All @@ -32,9 +36,9 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
$contribute[\ILIAS\Setup\Agent::class] = static fn() =>
$contribute[Agent::class] = static fn(): \ilADNAgent =>
new \ilADNAgent(
$pull[\ILIAS\Refinery\Factory::class]
$pull[Factory::class]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,22 @@ protected function getRecords(Order $order): array
$records = ilADNNotification::getArray();

// populate with additional data
array_walk($records, function (&$record) {
array_walk($records, function (array &$record): void {
$record['languages'] = $this->getLanguagesTextForNotification($record);
$record['type'] = $this->lng->txt("msg_type_" . $record['type']);
$record['event_start'] = $this->formatDate($record['event_start']);
$record['event_end'] = $this->formatDate($record['event_end']);
$record['display_start'] = $this->formatDate($record['display_start']);
$record['display_end'] = $this->formatDate($record['display_end']);

if (!$record['permanent']) {
$record['type_during_event'] = $this->lng->txt("msg_type_" . $record['type_during_event']);
} else {
$record['type_during_event'] = '';
}
$record['type_during_event'] = $record['permanent'] ? '' : $this->lng->txt("msg_type_" . $record['type_during_event']);
});

// sort
[$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
usort($records, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
[$order_field, $order_direction] = $order->join([], fn($ret, $key, $value): array => [$key, $value]);
usort($records, fn($a, $b): int => $a[$order_field] <=> $b[$order_field]);
if ($order_direction === 'DESC') {
$records = array_reverse($records);
return array_reverse($records);
}

return $records;
Expand Down Expand Up @@ -113,9 +109,7 @@ protected function getLanguagesTextForNotification(array $record): string
$languages_text = implode(
', ',
array_map(
function (string $lng_code): string {
return $this->lng->txt("meta_l_" . $lng_code);
},
fn(string $lng_code): string => $this->lng->txt("meta_l_" . $lng_code),
$limited_to_languages
)
);
Expand Down
Loading

0 comments on commit 91a5464

Please sign in to comment.