Skip to content

Commit 20256a4

Browse files
authored
Merge pull request #5965 from 3liz/backport-5962-to-release_3_9
[Backport release_3_9] PHP: Apply simplify if return bool from Rector
2 parents c4b3906 + 2e26fb0 commit 20256a4

File tree

10 files changed

+29
-95
lines changed

10 files changed

+29
-95
lines changed

lizmap/modules/lizmap/classes/lizmapServices.class.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,8 @@ public function getProperties()
525525

526526
public function hideSensitiveProperties()
527527
{
528-
if (isset($this->data['hideSensitiveServicesProperties'])
529-
&& $this->data['hideSensitiveServicesProperties'] != '0'
530-
) {
531-
return true;
532-
}
533-
534-
return false;
528+
return isset($this->data['hideSensitiveServicesProperties'])
529+
&& $this->data['hideSensitiveServicesProperties'] != '0';
535530
}
536531

537532
public function getSensitiveProperties()

lizmap/modules/lizmap/classes/qgisVectorLayer.class.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,13 +1091,10 @@ public function isFeatureEditable($feature)
10911091
// Return true or false depending of the resulting evaluation
10921092
if ($results && count($results) == 1) {
10931093
$result = $results[0];
1094-
if (property_exists($result, 'properties')
1095-
&& property_exists($result->properties, 'filterByLogin')
1096-
&& $result->properties->filterByLogin === 1) {
1097-
return true;
1098-
}
10991094

1100-
return false;
1095+
return property_exists($result, 'properties')
1096+
&& property_exists($result->properties, 'filterByLogin')
1097+
&& $result->properties->filterByLogin === 1;
11011098
}
11021099
}
11031100

@@ -1161,11 +1158,8 @@ public function isFeatureEditable($feature)
11611158

11621159
$featureStream = Psr7StreamWrapper::getResource($result->getBodyAsStream());
11631160
$features = JsonMachineItems::fromStream($featureStream, array('pointer' => '/features'));
1164-
if (iterator_count($features) !== 1) {
1165-
return false;
1166-
}
11671161

1168-
return true;
1162+
return iterator_count($features) === 1;
11691163
}
11701164

11711165
/**

lizmap/modules/lizmap/lib/Form/QgisFormValueRelationDynamicDatasource.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public function __construct($ref, $forceEmptyValue = false)
2121

2222
public function getForceEmptyValue()
2323
{
24-
if ($this->forceEmptyValue) {
25-
return true;
26-
}
27-
28-
return false;
24+
return (bool) $this->forceEmptyValue;
2925
}
3026

3127
public function setForceEmptyValue($forceEmptyValue)

lizmap/modules/lizmap/lib/Project/Project.php

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,8 @@ public function getWMSInformation()
753753
public function hasLocateByLayer()
754754
{
755755
$locate = $this->cfg->getLocateByLayer();
756-
if ($locate && count((array) $locate)) {
757-
return true;
758-
}
759756

760-
return false;
757+
return $locate && count((array) $locate);
761758
}
762759

763760
/**
@@ -797,11 +794,8 @@ public function hasPrintEnabled()
797794
public function hasFormFilterLayers()
798795
{
799796
$form = $this->cfg->getFormFilterLayers();
800-
if ($form && count((array) $form)) {
801-
return true;
802-
}
803797

804-
return false;
798+
return $form && count((array) $form);
805799
}
806800

807801
public function getFormFilterLayersConfig()
@@ -812,34 +806,25 @@ public function getFormFilterLayersConfig()
812806
public function hasTimemanagerLayers()
813807
{
814808
$timeManager = $this->cfg->getTimemanagerLayers();
815-
if ($timeManager && count((array) $timeManager)) {
816-
return true;
817-
}
818809

819-
return false;
810+
return $timeManager && count((array) $timeManager);
820811
}
821812

822813
public function hasAtlasEnabled()
823814
{
824815
$atlasEnabled = $this->cfg->getBooleanOption('atlasEnabled');
825816
$atlas = $this->cfg->getAtlas();
826817

827-
if ($atlasEnabled // Legacy LWC < 3.4 (only one layer)
828-
|| ($atlas && property_exists($atlas, 'layers') && count((array) $atlas->layers) > 0)) { // Multiple atlas
829-
return true;
830-
}
831-
832-
return false;
818+
// Multiple atlas
819+
return $atlasEnabled // Legacy LWC < 3.4 (only one layer)
820+
|| ($atlas && property_exists($atlas, 'layers') && count((array) $atlas->layers) > 0);
833821
}
834822

835823
public function hasTooltipLayers()
836824
{
837825
$tooltip = $this->cfg->getTooltipLayers();
838-
if ($tooltip && count((array) $tooltip)) {
839-
return true;
840-
}
841826

842-
return false;
827+
return $tooltip && count((array) $tooltip);
843828
}
844829

845830
public function hasAttributeLayers($onlyDisplayedLayers = false)
@@ -963,11 +948,7 @@ public function hasEditionLayersForCurrentUser()
963948
$this->readEditionLayersForCurrentUser();
964949
}
965950

966-
if (count($this->editionLayersForCurrentUser) != 0) {
967-
return true;
968-
}
969-
970-
return false;
951+
return count($this->editionLayersForCurrentUser) != 0;
971952
}
972953

973954
protected function readEditionLayersForCurrentUser()
@@ -1168,11 +1149,8 @@ public function findEditionLayerByLayerId($layerId)
11681149
public function hasLoginFilteredLayers()
11691150
{
11701151
$login = (array) $this->cfg->getLoginFilteredLayers();
1171-
if (count((array) $login) > 0) {
1172-
return true;
1173-
}
11741152

1175-
return false;
1153+
return count((array) $login) > 0;
11761154
}
11771155

11781156
/**
@@ -1406,11 +1384,7 @@ public function hasPolygonFilteredLayers()
14061384
return false;
14071385
}
14081386

1409-
if (array_key_exists('layers', $filter_config) && count($filter_config['layers']) > 0) {
1410-
return true;
1411-
}
1412-
1413-
return false;
1387+
return array_key_exists('layers', $filter_config) && count($filter_config['layers']) > 0;
14141388
}
14151389

14161390
/**
@@ -2554,11 +2528,8 @@ public function getDefaultRightDockable()
25542528
public function needsUpdateError()
25552529
{
25562530
$requiredTargetLwcVersion = \jApp::config()->minimumRequiredVersion['lizmapWebClientTargetVersion'];
2557-
if ($this->getLizmapWebClientTargetVersion() < $requiredTargetLwcVersion) {
2558-
return true;
2559-
}
25602531

2561-
return false;
2532+
return $this->getLizmapWebClientTargetVersion() < $requiredTargetLwcVersion;
25622533
}
25632534

25642535
/**
@@ -2569,11 +2540,8 @@ public function needsUpdateError()
25692540
public function needsUpdateWarning()
25702541
{
25712542
$requiredTargetLwcVersion = \jApp::config()->minimumRequiredVersion['lizmapWebClientTargetVersion'];
2572-
if ($this->getLizmapWebClientTargetVersion() == $requiredTargetLwcVersion) {
2573-
return true;
2574-
}
25752543

2576-
return false;
2544+
return $this->getLizmapWebClientTargetVersion() == $requiredTargetLwcVersion;
25772545
}
25782546

25792547
/**
@@ -2660,11 +2628,8 @@ public function checkAcl()
26602628

26612629
// Check if configured groups white list and authenticated user groups list intersects
26622630
$userGroups = $this->appContext->aclUserGroupsId();
2663-
if (array_intersect($aclGroups, $userGroups)) {
2664-
return true;
2665-
}
26662631

2667-
return false;
2632+
return (bool) array_intersect($aclGroups, $userGroups);
26682633
}
26692634

26702635
/**
@@ -2691,11 +2656,8 @@ public function checkAclByUser($login)
26912656

26922657
// Check if configured groups white list and authenticated user groups list intersects
26932658
$userGroups = $this->appContext->aclGroupsIdByUser($login);
2694-
if (array_intersect($aclGroups, $userGroups)) {
2695-
return true;
2696-
}
26972659

2698-
return false;
2660+
return (bool) array_intersect($aclGroups, $userGroups);
26992661
}
27002662

27012663
/**

lizmap/modules/lizmap/lib/Project/ProjectConfig.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,7 @@ public function getEditionLayerByLayerId($layerId)
405405
*/
406406
public function hasEditionLayers()
407407
{
408-
if (count((array) $this->editionLayers)) {
409-
return true;
410-
}
411-
412-
return false;
408+
return (bool) count((array) $this->editionLayers);
413409
}
414410

415411
/**

lizmap/modules/lizmap/lib/Project/ProjectMainData.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,8 @@ protected function checkAcl($cfgContent, $appContext)
474474

475475
// Check if configured groups white list and authenticated user groups list intersects
476476
$userGroups = $appContext->aclUserGroupsId();
477-
if (array_intersect($aclGroups, $userGroups)) {
478-
return true;
479-
}
480477

481-
return false;
478+
return (bool) array_intersect($aclGroups, $userGroups);
482479
}
483480

484481
/**

lizmap/modules/lizmap/lib/Project/ProjectMetadata.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,9 @@ public function qgisLizmapPluginUpdateNeeded()
270270

271271
// We check against the hard coded version number
272272
$recommendedVersion = \jApp::config()->minimumRequiredVersion['lizmapDesktopPlugin'];
273-
if ($recommendedVersion <= $lizmapProjectVersion) {
274-
// Lizmap plugin version in the CFG file is newer than the hard coded version
275-
return false;
276-
}
277273

278-
return true;
274+
// Lizmap plugin version in the CFG file is newer than the hard coded version
275+
return $recommendedVersion > $lizmapProjectVersion;
279276
}
280277

281278
/**

lizmap/modules/lizmap/lib/Request/WFSRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function getEditingContext()
7171
*
7272
* @return bool The edition context for request
7373
*/
74-
public function setEditingContext($editingContext)
74+
public function setEditingContext(bool $editingContext): bool
7575
{
76-
$this->editingContext = $editingContext ? true : false;
76+
$this->editingContext = $editingContext;
7777

7878
return $this->editingContext;
7979
}

lizmap/modules/lizmap/lib/Request/WMSRequest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,8 @@ protected function checkMaximumWidthHeight()
261261
$max = $this->services->wmsMaxHeight ?: 3000;
262262
}
263263
$dim = $this->param('height');
264-
if ($dim == null || !is_numeric($dim) || intval($dim) > $max) {
265-
return false;
266-
}
267264

268-
return true;
265+
return !($dim == null || !is_numeric($dim) || intval($dim) > $max);
269266
}
270267

271268
/**

tests/units/rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Set the level of type coverage
88
$levelTypeCoverage = 5;
99
$levelDeadCode = 1;
10-
$levelCodeQuality = 10;
10+
$levelCodeQuality = 12;
1111

1212
function getLevelTypeCoverage(): int
1313
{

0 commit comments

Comments
 (0)