Skip to content

Commit

Permalink
Shut up some phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
inxomnyaa committed Oct 5, 2022
1 parent 5308f14 commit 5c92b84
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/xenialdan/MagicWE2/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public static function getRotationData(BlockState $blockState, int $rotation) :
return API::$rotationData[$id . ":" . $meta][(string) $rotation] ?? [];
}

public static function setRotationData(array $json){
public static function setRotationData(array $json) : void{
self::$rotationData = $json;
}

Expand Down
9 changes: 0 additions & 9 deletions src/xenialdan/MagicWE2/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ private function onBreakBlock(BlockBreakEvent $event) : void{
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $event->getBlock()->getPosition()->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$selection->setPos1($event->getBlock()->getPosition());
break;
}
Expand Down Expand Up @@ -241,9 +238,6 @@ private function onRightClickBlock(PlayerInteractEvent $event) : void{
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $event->getBlock()->getPosition()->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$selection->setPos2($event->getBlock()->getPosition());
break;
}
Expand Down Expand Up @@ -321,9 +315,6 @@ private function onLeftClickBlock(PlayerInteractEvent $event) : void{
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $event->getBlock()->getPosition()->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$selection->setPos1($event->getBlock()->getPosition());
break;
}
Expand Down
3 changes: 0 additions & 3 deletions src/xenialdan/MagicWE2/commands/selection/ChunkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $sender->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$chunk = $sender->getWorld()->getOrLoadChunkAtPosition($sender->getPosition());
if(is_null($chunk)){
throw new Error("Could not find a chunk at your position");
Expand Down
4 changes: 0 additions & 4 deletions src/xenialdan/MagicWE2/commands/selection/HPos1Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use xenialdan\MagicWE2\Loader;
use xenialdan\MagicWE2\selection\Selection;
use xenialdan\MagicWE2\session\UserSession;
use function is_null;

class HPos1Command extends BaseCommand{

Expand Down Expand Up @@ -53,9 +52,6 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $sender->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance());
if($target === null){
$sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget'));
Expand Down
4 changes: 0 additions & 4 deletions src/xenialdan/MagicWE2/commands/selection/HPos2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use xenialdan\MagicWE2\Loader;
use xenialdan\MagicWE2\selection\Selection;
use xenialdan\MagicWE2\session\UserSession;
use function is_null;

class HPos2Command extends BaseCommand{

Expand Down Expand Up @@ -53,9 +52,6 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $sender->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$target = $sender->getTargetBlock(Loader::getInstance()->getToolDistance());
if($target === null){
$sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.notarget'));
Expand Down
4 changes: 0 additions & 4 deletions src/xenialdan/MagicWE2/commands/selection/Pos1Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use xenialdan\MagicWE2\Loader;
use xenialdan\MagicWE2\selection\Selection;
use xenialdan\MagicWE2\session\UserSession;
use function is_null;

class Pos1Command extends BaseCommand{

Expand Down Expand Up @@ -53,9 +52,6 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $sender->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$selection->setPos1($sender->getPosition());
} catch (Exception $error) {
Loader::getInstance()->getLogger()->logException($error);
Expand Down
4 changes: 0 additions & 4 deletions src/xenialdan/MagicWE2/commands/selection/Pos2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use xenialdan\MagicWE2\Loader;
use xenialdan\MagicWE2\selection\Selection;
use xenialdan\MagicWE2\session\UserSession;
use function is_null;

class Pos2Command extends BaseCommand{

Expand Down Expand Up @@ -53,9 +52,6 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
if(($selection = $session->getLatestSelection()) === null){
$session->addSelection(($selection = new Selection($session->getUUID(), $sender->getWorld()))); // TODO check if the selection inside of the session updates
}
if(is_null($selection)){
throw new Error("No selection created - Check the console for errors");
}
$selection->setPos2($sender->getPosition());
} catch (Exception $error) {
Loader::getInstance()->getLogger()->logException($error);
Expand Down
8 changes: 4 additions & 4 deletions src/xenialdan/MagicWE2/commands/tool/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ protected function prepare(): void
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void
{
$lang = Loader::getInstance()->getLanguage();
if ($sender instanceof Player && SessionHelper::hasSession($sender)) {
try {
if($sender instanceof Player && ($session = SessionHelper::hasSession($sender))){
try{
$lang = SessionHelper::getUserSession($sender)->getLanguage();
} catch (SessionException) {
}catch(SessionException){
}
}
if (!$sender instanceof Player) {
if(!$sender instanceof Player){
$sender->sendMessage(TF::RED . $lang->translateString('error.runingame'));
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/xenialdan/MagicWE2/helper/ArrayUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ArrayUtils{

public static function advanceWrap(&$array) : array{
public static function advanceWrap(array &$array) : array{
$result = [key($array), current($array)];
if(!self::hasNext($array)){
reset($array);
Expand All @@ -19,7 +19,7 @@ public static function advanceWrap(&$array) : array{
return $result;
}

public static function regressWrap(&$array) : array{
public static function regressWrap(array &$array) : array{
$return = [key($array), current($array)];
if(!self::hasPrev($array)){
end($array);
Expand All @@ -37,7 +37,7 @@ public static function hasPrev(array $array) : bool{
return prev($array) !== false || key($array) !== null;
}

public static function setPointerToValue(array &$array, $value) : void{
public static function setPointerToValue(array &$array, mixed $value) : void{
reset($array);
#var_dump($array,current($array),$value);
while(current($array) !== $value && self::hasNext($array)) next($array);
Expand Down
4 changes: 2 additions & 2 deletions src/xenialdan/MagicWE2/selection/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function setShape(Shape $shape) : void{
// $manager = $this->getIterator()->getManager();
// if($manager instanceof AsyncWorld) $manager->copyChunks($this);
}catch(RuntimeException | SelectionException $e){
Loader::getInstance()->getLogger()->debug($e);
Loader::getInstance()->getLogger()->debug($e->getMessage());
}
}

Expand All @@ -220,7 +220,7 @@ public function isValid() : bool{
$this->getPos1();
$this->getPos2();
}catch(Exception $e){
Loader::getInstance()->getLogger()->debug($e);
Loader::getInstance()->getLogger()->debug($e->getMessage());
return false;
}
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/xenialdan/MagicWE2/session/data/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function __construct(string $filename, Schematic|SingleClipboard|MCStruct

public function getSize(): Vector3
{
if ($this->structure instanceof Schematic) return new Vector3($this->structure->getWidth(), $this->structure->getHeight(), $this->structure->getLength());
if ($this->structure instanceof MCStructure) return $this->structure->getSize();
if($this->structure instanceof Schematic) return new Vector3($this->structure->getWidth(), $this->structure->getHeight(), $this->structure->getLength());
if($this->structure instanceof MCStructure) return new Vector3($this->structure->getSize()->getX(), $this->structure->getSize()->getY(), $this->structure->getSize()->getZ());
else return new Vector3($this->structure->selection->getSizeX(), $this->structure->selection->getSizeY(), $this->structure->selection->getSizeZ());
//throw new Exception("Unknown structure type");
}
Expand All @@ -81,8 +81,8 @@ public function getTotalCount(): int

public function getOrigin(): Vector3
{
if ($this->structure instanceof Schematic) return new Vector3(0, 0, 0);
if ($this->structure instanceof MCStructure) return $this->structure->getStructureWorldOrigin();
if($this->structure instanceof Schematic) return new Vector3(0, 0, 0);
if($this->structure instanceof MCStructure) return new Vector3($this->structure->getStructureWorldOrigin()->getX(), $this->structure->getStructureWorldOrigin()->getY(), $this->structure->getStructureWorldOrigin()->getZ());
else return $this->structure->position;
//throw new Exception("Unknown structure type");
}
Expand Down
4 changes: 2 additions & 2 deletions src/xenialdan/MagicWE2/task/AsyncRevertTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function undoChunks(AsyncWorld &$manager, RevertClipboard $clipboard) :
//$block is "data" array
foreach($clipboard->blocksAfter as $block){
$block = self::singleDataToBlock($block);//turn data into real block
$original = $manager->getBlockAt($block->getPosition()->x, $block->getPosition()->y, $block->getPosition()->z);
$original = $manager->getBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ());
yield self::singleBlockToData($original, $block->getPosition());
$manager->setBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ(), $block);
$changed++;
Expand All @@ -115,7 +115,7 @@ private function redoChunks(AsyncWorld &$manager, RevertClipboard $clipboard) :
//$block is "data" array
foreach($clipboard->blocksAfter as $block){
$block = self::singleDataToBlock($block);//turn data into real block
$original = $manager->getBlockAt($block->getPosition()->x, $block->getPosition()->y, $block->getPosition()->z);
$original = $manager->getBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ());
yield self::singleBlockToData($original, $block->getPosition());
$manager->setBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ(), $block);
$changed++;
Expand Down
6 changes: 3 additions & 3 deletions src/xenialdan/MagicWE2/tool/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function toItem(Language $lang) : Item{

public function getCurrentState(string $blockIdentifier) : ?string{
if(array_key_exists($blockIdentifier, $this->states)){
return key($this->states[$blockIdentifier]);
return (string) ($this->states[$blockIdentifier]);
}
return null;
}
Expand All @@ -117,7 +117,7 @@ public function getName() : string{
* @throws InvalidArgumentException
* @throws AssumptionFailedError
*/
public function useSecondary(UserSession $session, Block $block){
public function useSecondary(UserSession $session, Block $block) : void{
//cycle values
/** @var BlockStatesParser $blockStatesParser */
$blockStatesParser = BlockStatesParser::getInstance();
Expand Down Expand Up @@ -155,7 +155,7 @@ public function useSecondary(UserSession $session, Block $block){
}
}

public function usePrimary(UserSession $session, Block $block){
public function usePrimary(UserSession $session, Block $block) : void{
//cycle states
/** @var BlockStatesParser $blockStatesParser */
$blockStatesParser = BlockStatesParser::getInstance();
Expand Down

0 comments on commit 5c92b84

Please sign in to comment.