Skip to content

Commit

Permalink
Merge pull request #4142 from mjansenDatabay/review/8/php8-uicomponent
Browse files Browse the repository at this point in the history
PHP 8: Code Review `UIComponent`
  • Loading branch information
alex40724 authored Mar 17, 2022
2 parents f326ace + 5f8f429 commit 99a5b2c
Show file tree
Hide file tree
Showing 31 changed files with 342 additions and 385 deletions.
1 change: 0 additions & 1 deletion Services/Skill/classes/class.ilSkillSelectorGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ilSkillSelectorGUI extends ilVirtualSkillTreeExplorerGUI
protected $select_gui = "";
protected string $select_cmd = "";
protected string $select_par = "";
protected bool $select_multi = false;
protected SkillAdminGUIRequest $admin_gui_request;
protected array $requested_selected_ids = [];

Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Services/UIComponent/Button/classes/class.ilButtonBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function renderAttributesHelper(array $a_attr) : string
}
}

if (sizeof($res)) {
if (count($res)) {
return " " . implode(" ", $res);
}
return "";
Expand All @@ -200,7 +200,7 @@ protected function renderAttributes(array $a_additional_attr = null) : string
$attr["disabled"] = "disabled";
}

if (sizeof($a_additional_attr)) {
if (count($a_additional_attr)) {
$attr = array_merge($attr, $a_additional_attr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function getInstance() : self
// properties
//

public function setImage(string $a_value, bool $a_is_internal = true)
public function setImage(string $a_value, bool $a_is_internal = true) : void
{
if ($a_is_internal) {
$a_value = ilUtil::getImagePath($a_value);
Expand Down
2 changes: 1 addition & 1 deletion Services/UIComponent/Button/classes/class.ilLinkButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getUrl() : string
return $this->url;
}

public function setTarget(string $a_value)
public function setTarget(string $a_value) : void
{
$this->target = trim($a_value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function _isAllowed() : bool
// with correct case for checking parent classes
$class = false;
foreach ($ilCtrl->getCallHistory() as $call) {
if ($call['mode'] == 'execComm') {
if ($call['mode'] === 'execComm') {
$class = $call['class'];
}
}
Expand Down Expand Up @@ -237,7 +237,11 @@ public function addToPage() : void
$tpl->addCss(ilUtil::getStyleSheetLocation('', 'char_selector_style.css', 'Services/UIComponent/CharSelector'));
$tpl->addJavaScript('./Services/UIComponent/CharSelector/js/ilCharSelector.js');
$tpl->addLightbox($this->getSelectorHTML(), 2);
$tpl->addOnLoadCode('il.CharSelector.init(' . json_encode($this->jsconfig) . ',' . json_encode($this->jstexts) . ')');
$tpl->addOnLoadCode(
'il.CharSelector.init(' .
json_encode($this->jsconfig, JSON_THROW_ON_ERROR) . ',' .
json_encode($this->jstexts, JSON_THROW_ON_ERROR) . ')'
);
$this->added_to_page = true;
}

Expand Down Expand Up @@ -295,7 +299,7 @@ public function saveState() : void
'open' => ilSession::get('char_selector_open'),
'current_page' => ilSession::get('char_selector_current_page'),
'current_subpage' => ilSession::get('char_selector_current_subpage'),
));
), JSON_THROW_ON_ERROR);
exit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function checkInput() : bool
return false;
}

if ($this->int('char_selector_availability') == ilCharSelectorConfig::ENABLED
and trim(implode("", $this->strArray('char_selector_blocks'))) == ""
and trim($this->str('char_selector_custom_items')) == '') {
if ($this->int('char_selector_availability') === ilCharSelectorConfig::ENABLED
&& trim(implode("", $this->strArray('char_selector_blocks'))) === ""
&& trim($this->str('char_selector_custom_items')) === '') {
$this->setAlert($lng->txt("char_selector_msg_blocks_or_custom_needed"));
return false;
} else {
Expand Down
36 changes: 17 additions & 19 deletions Services/UIComponent/CharSelector/classes/ilCharSelectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static function _getCurrentConfig(ilObjTest $a_test_obj = null) : self
$admin_config = new self(self::CONTEXT_ADMIN);
$admin_config->setAvailability($ilSetting->get('char_selector_availability'));
$admin_config->setDefinition($ilSetting->get('char_selector_definition'));
if ($admin_config->getAvailability() == self::INACTIVE) {
if ($admin_config->getAvailability() === self::INACTIVE) {
// a globally inactive selector can't be overwritten by users or tests
return $admin_config;
}
Expand All @@ -312,7 +312,7 @@ public static function _getCurrentConfig(ilObjTest $a_test_obj = null) : self
$test_config = new self(self::CONTEXT_TEST);
$test_config->setAvailability($a_test_obj->getCharSelectorAvailability());
$test_config->setDefinition($a_test_obj->getCharSelectorDefinition());
if ($test_config->getAvailability() != self::INHERIT) {
if ($test_config->getAvailability() !== self::INHERIT) {
// a specific test configuration has precedence over user configuration
return $test_config;
}
Expand All @@ -322,7 +322,7 @@ public static function _getCurrentConfig(ilObjTest $a_test_obj = null) : self
$user_config = new self(self::CONTEXT_USER);
$user_config->setAvailability($ilUser->getPref('char_selector_availability'));
$user_config->setDefinition($ilUser->getPref('char_selector_definition'));
if ($user_config->getAvailability() != self::INHERIT) {
if ($user_config->getAvailability() !== self::INHERIT) {
// take user specific config
return $user_config;
} else {
Expand Down Expand Up @@ -367,9 +367,8 @@ public function setAddedBlocks(array $a_blocks = array()) : void
{
$this->added_blocks = array();
foreach ($a_blocks as $block_name) {
if ($block_name == "all" or
in_array($block_name, array_keys(self::$unicode_blocks))) {
array_push($this->added_blocks, $block_name);
if ($block_name === "all" || array_key_exists($block_name, self::$unicode_blocks)) {
$this->added_blocks[] = $block_name;
}
}
}
Expand Down Expand Up @@ -420,17 +419,17 @@ public function setDefinition(string $a_definition = '') : void
$this->custom_items = array();

// set the default definition to all unicode blocks
if (trim($a_definition) == '') {
if (trim($a_definition) === '') {
$a_definition = "[all]";
}

// analyze definition items
$items = explode(' ', $a_definition);
foreach ($items as $item) {
if (strlen($block_name = $this->extractUnicodeBlock($item))) {
array_push($this->added_blocks, $block_name);
} elseif ($item != '') {
array_push($this->custom_items, trim($item));
if (($block_name = $this->extractUnicodeBlock($item)) !== '') {
$this->added_blocks[] = $block_name;
} elseif ($item !== '') {
$this->custom_items[] = trim($item);
}
}
}
Expand All @@ -443,7 +442,7 @@ public function getDefinition() : string
{
$definition = implode(' ', $this->custom_items);
foreach ($this->added_blocks as $block_name) {
$definition = $definition . ' [' . $block_name . ']';
$definition .= ' [' . $block_name . ']';
}
return trim($definition);
}
Expand Down Expand Up @@ -476,7 +475,7 @@ public function getBlockTitle(string $a_block_name) : string
global $lng;

$langvar = 'char_selector_unicode_' . $a_block_name;
if ($lng->txt($langvar) != '-' . $langvar . '-') {
if ($lng->txt($langvar) !== '-' . $langvar . '-') {
return $lng->txt($langvar);
} else {
return self::$unicode_blocks[$a_block_name][0];
Expand All @@ -494,8 +493,7 @@ private function extractUnicodeBlock(string $a_item = '') : string
$matches = array();
if (preg_match('/^\[(.+)\]$/', $a_item, $matches)) {
$block_name = $matches[1];
if ($block_name == 'all'
or in_array($block_name, array_keys(self::$unicode_blocks))) {
if ($block_name === 'all' || array_key_exists($block_name, self::$unicode_blocks)) {
return $block_name;
}
}
Expand Down Expand Up @@ -523,14 +521,14 @@ public function getCharPages() : array
$subitems = explode('-', $item);
$start = $this->getItemCodepoint($subitems[0]);
$end = $this->getItemCodepoint($subitems[1]);
array_push($page, array($start, $end));
$page[] = array($start, $end);
} else {
// handle normal item
array_push($page, $this->getItemParsed($item));
$page[] = $this->getItemParsed($item);
}
}
if (count($page) > 1) {
array_push($pages, $page);
$pages[] = $page;
}

// add unicode blocks
Expand All @@ -543,7 +541,7 @@ public function getCharPages() : array
$start = hexdec(self::$unicode_blocks[$block_name][1]);
$end = hexdec(self::$unicode_blocks[$block_name][2]);
$page = array($this->getBlockTitle($block_name), array($start, $end));
array_push($pages, $page);
$pages[] = $page;
}

return $pages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function __construct(
$this->setId($a_id);
}

public function setId($a_val)
public function setId(string $a_val) : void
{
$this->id = $a_val;
}

public function getId()
public function getId() : string
{
return $this->id;
}
Expand Down
Loading

0 comments on commit 99a5b2c

Please sign in to comment.