Skip to content
This repository was archived by the owner on Oct 29, 2022. It is now read-only.

Commit 21905bc

Browse files
authored
Passing PHPStan level 7 (#364)
1 parent 80e31f8 commit 21905bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+391
-830
lines changed

phpstan.neon.dist

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
parameters:
2-
level: 7
3-
checkMissingIterableValueType: false
4-
reportUnmatchedIgnoredErrors: false
5-
paths:
6-
- /source/src
7-
- /deps
8-
autoload_files:
9-
- phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php
10-
autoload_directories:
11-
- /source/src
12-
- /deps
13-
excludes_analyse:
14-
- /deps
2+
level: 7
3+
paths:
4+
- /source/src
5+
scanDirectories:
6+
- /source/src
7+
- /deps
8+
bootstrapFiles:
9+
- phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: MyPlot
22
main: MyPlot\MyPlot
3-
version: 1.9.0
3+
version: 1.10.0
44
api:
55
- 3.4.0
66
authors:

src/MyPlot/Commands.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function __construct(MyPlot $plugin) {
116116
preg_match_all('/(\s?[<\[]?\s*)([a-zA-Z0-9|]+)(?:\s*:?\s*)(string|int|x y z|float|mixed|target|message|text|json|command|boolean|bool)?(?:\s*[>\]]?\s?)/iu', $usage, $matches, PREG_PATTERN_ORDER, strlen($commandString));
117117
$argumentCount = count($matches[0])-1;
118118
for($argNumber = 1; $argNumber <= $argumentCount; ++$argNumber) {
119-
$optional = empty($matches[1][$argNumber]) ? false : ($matches[1][$argNumber] === '[');
119+
$optional = $matches[1][$argNumber] === '' ? false : ($matches[1][$argNumber] === '[');
120120
$paramName = strtolower($matches[2][$argNumber]);
121121
if(stripos($paramName, "|") === false) {
122122
switch(strtolower($matches[3][$argNumber])) {
@@ -189,19 +189,13 @@ public function getCommands() : array {
189189
return $this->subCommands;
190190
}
191191

192-
/**
193-
* @param SubCommand $command
194-
*/
195192
public function loadSubCommand(SubCommand $command) : void {
196193
$this->subCommands[$command->getName()] = $command;
197194
if($command->getAlias() != "") {
198195
$this->aliasSubCommands[$command->getAlias()] = $command;
199196
}
200197
}
201198

202-
/**
203-
* @param string $name
204-
*/
205199
public function unloadSubCommand(string $name) : void {
206200
$subcommand = $this->subCommands[$name] ?? $this->aliasSubCommands[$name] ?? null;
207201
if($subcommand !== null) {
@@ -232,7 +226,7 @@ public function execute(CommandSender $sender, string $alias, array $args) : boo
232226
return true;
233227
}
234228
}
235-
$subCommand = strtolower(array_shift($args));
229+
$subCommand = strtolower((string)array_shift($args));
236230
if(isset($this->subCommands[$subCommand])) {
237231
$command = $this->subCommands[$subCommand];
238232
}elseif(isset($this->aliasSubCommands[$subCommand])) {

src/MyPlot/EventListener.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ public function onLevelLoad(LevelLoadEvent $event) : void {
5151
if(file_exists($this->plugin->getDataFolder()."worlds".DIRECTORY_SEPARATOR.$event->getLevel()->getFolderName().".yml")) {
5252
$this->plugin->getLogger()->debug("MyPlot level " . $event->getLevel()->getFolderName() . " loaded!");
5353
$settings = $event->getLevel()->getProvider()->getGeneratorOptions();
54-
if(!isset($settings["preset"]) or empty($settings["preset"])) {
54+
if(!isset($settings["preset"]) or !is_string($settings["preset"]) or $settings["preset"] === "") {
5555
return;
5656
}
5757
$settings = json_decode($settings["preset"], true);
5858
if($settings === false) {
5959
return;
6060
}
6161
$levelName = $event->getLevel()->getFolderName();
62-
$default = array_filter($this->plugin->getConfig()->get("DefaultWorld", []), function($key){
63-
return !in_array($key, ["PlotSize", "GroundHeight", "RoadWidth", "RoadBlock", "WallBlock", "PlotFloorBlock", "PlotFillBlock", "BottomBlock"]);
62+
$default = array_filter((array) $this->plugin->getConfig()->get("DefaultWorld", []), function($key) : bool {
63+
return !in_array($key, ["PlotSize", "GroundHeight", "RoadWidth", "RoadBlock", "WallBlock", "PlotFloorBlock", "PlotFillBlock", "BottomBlock"], true);
6464
}, ARRAY_FILTER_USE_KEY);
6565
$config = new Config($this->plugin->getDataFolder()."worlds".DIRECTORY_SEPARATOR.$levelName.".yml", Config::YAML, $default);
6666
foreach(array_keys($default) as $key) {
@@ -134,7 +134,7 @@ public function onSignChange(SignChangeEvent $event) : void {
134134
private function onEventOnBlock($event) : void {
135135
if(!$event->getBlock()->isValid())
136136
return;
137-
$levelName = $event->getBlock()->getLevel()->getFolderName();
137+
$levelName = $event->getBlock()->getLevelNonNull()->getFolderName();
138138
if(!$this->plugin->isLevelLoaded($levelName)) {
139139
return;
140140
}
@@ -198,7 +198,7 @@ public function onExplosion(EntityExplodeEvent $event) : void {
198198
if($event->isCancelled()) {
199199
return;
200200
}
201-
$levelName = $event->getEntity()->getLevel()->getFolderName();
201+
$levelName = $event->getEntity()->getLevelNonNull()->getFolderName();
202202
if(!$this->plugin->isLevelLoaded($levelName))
203203
return;
204204
$plot = $this->plugin->getPlotByPosition($event->getPosition());
@@ -208,10 +208,11 @@ public function onExplosion(EntityExplodeEvent $event) : void {
208208
}
209209
$beginPos = $this->plugin->getPlotPosition($plot);
210210
$endPos = clone $beginPos;
211-
$plotSize = $this->plugin->getLevelSettings($levelName)->plotSize;
211+
$levelSettings = $this->plugin->getLevelSettings($levelName);
212+
$plotSize = $levelSettings->plotSize;
212213
$endPos->x += $plotSize;
213214
$endPos->z += $plotSize;
214-
$blocks = array_filter($event->getBlockList(), function($block) use ($beginPos, $endPos) {
215+
$blocks = array_filter($event->getBlockList(), function($block) use ($beginPos, $endPos) : bool {
215216
if($block->x >= $beginPos->x and $block->z >= $beginPos->z and $block->x < $endPos->x and $block->z < $endPos->z) {
216217
return true;
217218
}
@@ -253,7 +254,7 @@ public function onBlockSpread(BlockSpreadEvent $event) : void {
253254
if($event->isCancelled()) {
254255
return;
255256
}
256-
$levelName = $event->getBlock()->getLevel()->getFolderName();
257+
$levelName = $event->getBlock()->getLevelNonNull()->getFolderName();
257258
if(!$this->plugin->isLevelLoaded($levelName))
258259
return;
259260
$settings = $this->plugin->getLevelSettings($levelName);
@@ -305,16 +306,17 @@ public function onPlayerTeleport(EntityTeleportEvent $event) : void {
305306
}
306307

307308
/**
309+
* @param Player $player
308310
* @param PlayerMoveEvent|EntityTeleportEvent $event
309311
*/
310312
private function onEventOnMove(Player $player, $event) : void {
311-
$levelName = $player->getLevel()->getFolderName();
313+
$levelName = $player->getLevelNonNull()->getFolderName();
312314
if (!$this->plugin->isLevelLoaded($levelName))
313315
return;
314316
$plot = $this->plugin->getPlotByPosition($event->getTo());
315317
$plotFrom = $this->plugin->getPlotByPosition($event->getFrom());
316318
if($plot !== null and ($plotFrom === null or !$plot->isSame($plotFrom))) {
317-
if(strpos((string) $plot, "-0")) {
319+
if(strpos((string) $plot, "-0") !== false) {
318320
return;
319321
}
320322
$ev = new MyPlotPlayerEnterPlotEvent($plot, $player);
@@ -328,11 +330,11 @@ private function onEventOnMove(Player $player, $event) : void {
328330
if($event->isCancelled()) {
329331
return;
330332
}
331-
if(!$this->plugin->getConfig()->get("ShowPlotPopup", true))
333+
if(!(bool) $this->plugin->getConfig()->get("ShowPlotPopup", true))
332334
return;
333335
$popup = $this->plugin->getLanguage()->translateString("popup", [TextFormat::GREEN . $plot]);
334336
$price = TextFormat::GREEN . $plot->price;
335-
if(!empty($plot->owner)) {
337+
if($plot->owner !== "") {
336338
$owner = TextFormat::GREEN . $plot->owner;
337339
if($plot->price > 0 and $plot->owner !== $player->getName()) {
338340
$ownerPopup = $this->plugin->getLanguage()->translateString("popup.forsale", [$owner.TextFormat::WHITE, $price.TextFormat::WHITE]);
@@ -348,15 +350,15 @@ private function onEventOnMove(Player $player, $event) : void {
348350
$popup = TextFormat::WHITE . $paddingPopup . $popup . "\n" . TextFormat::WHITE . $paddingOwnerPopup . $ownerPopup;
349351
$ev->getPlayer()->sendTip($popup);
350352
}elseif($plotFrom !== null and ($plot === null or !$plot->isSame($plotFrom))) {
351-
if(strpos((string) $plotFrom, "-0")) {
353+
if(strpos((string) $plotFrom, "-0") !== false) {
352354
return;
353355
}
354356
$ev = new MyPlotPlayerLeavePlotEvent($plotFrom, $player);
355357
$ev->setCancelled($event->isCancelled());
356358
$ev->call();
357359
$event->setCancelled($ev->isCancelled());
358360
}elseif($plotFrom !== null and $plot !== null and ($plot->isDenied($player->getName()) or $plot->isDenied("*")) and $plot->owner !== $player->getName() and !$player->hasPermission("myplot.admin.denyplayer.bypass")) {
359-
$this->plugin->teleportPlayerToPlot($player, $plot, false);
361+
$this->plugin->teleportPlayerToPlot($player, $plot);
360362
}
361363
}
362364

@@ -370,7 +372,7 @@ public function onEntityDamage(EntityDamageByEntityEvent $event) : void {
370372
$damaged = $event->getEntity();
371373
$damager = $event->getDamager();
372374
if($damaged instanceof Player and $damager instanceof Player and !$event->isCancelled()) {
373-
$levelName = $damaged->getLevel()->getFolderName();
375+
$levelName = $damaged->getLevelNonNull()->getFolderName();
374376
if(!$this->plugin->isLevelLoaded($levelName)) {
375377
return;
376378
}

0 commit comments

Comments
 (0)