Skip to content

Commit

Permalink
Refer to get_class results as strings
Browse files Browse the repository at this point in the history
get_class returns a string not a type.

Using the bare class name is now a fatal error in PHP 8.
  • Loading branch information
bakert committed Jan 3, 2022
1 parent b75c6b7 commit 369dd8b
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions board.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function applyWithoutChecks(Move $move, $updateLocations = false) {
}
}
}
return $board;
return $this->board;
}

private function addLocation(Point $pointToAdd) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public function score(Move $move) {
$board = clone $this;
$board->applyWithoutChecks($move);
$lines = $move->lines($board);
$points = 0;
$score = 0;
foreach ($lines as $line) {
if ($line->length() === count(Color::colors())) {
$score += Score::QWIRKLE_BONUS;
Expand Down Expand Up @@ -147,6 +147,7 @@ public function __toString() {
$leftmost -= 1;
$rightmost += 2;

$s = '';
for ($y = $highest; $y < $lowest; $y++) {
$a = [];
for ($x = $leftmost; $x < $rightmost; $x++) {
Expand Down
2 changes: 1 addition & 1 deletion event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Event {
public function draw(Player $player, array $tiles) {
Assert::type($tiles, Tile);
Assert::type($tiles, 'Tile');
$hand = new Hand($tiles);
$this->p("{$player} draws {$hand}");
if (count($tiles) < $player->hand()->size()) {
Expand Down
4 changes: 2 additions & 2 deletions game.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Game {
private $scores;

public function __construct(array $players, $tiles = null) {
Assert::type($players, Player);
Assert::type($players, 'Player');
$this->players = $players;
$this->random = $tiles === null;
$this->tiles = $tiles;
Expand Down Expand Up @@ -67,7 +67,7 @@ public function go() {
}
}
}
$event->gameEnd($scores);
$event->gameEnd($this->scores);
}

public function scores() {
Expand Down
2 changes: 1 addition & 1 deletion hand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Hand {
use Tiles;

public function __construct(array $tiles = []) {
Assert::type($tiles, Tile);
Assert::type($tiles, 'Tile');
$this->tiles = $tiles;
}

Expand Down
2 changes: 1 addition & 1 deletion line.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Line {
use Tiles;

public function __construct(array $placements = []) {
Assert::type($placements, Placement);
Assert::type($placements, 'Placement');
$this->placements = $placements;
}

Expand Down
2 changes: 1 addition & 1 deletion move.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Move {
const STARTING_INDEX = 99;

public function __construct($placements) {
Assert::type($placements, Placement);
Assert::type($placements, 'Placement');
$this->placements = $placements;
}

Expand Down
2 changes: 1 addition & 1 deletion player.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function discard() {
}

public function startingMove(array $tiles) {
Assert::type($tiles, Tile);
Assert::type($tiles, 'Tile');
$lines = [];
foreach ($tiles as $tile) {
if (!isset($lines[$tile->color()->name()])) {
Expand Down
4 changes: 2 additions & 2 deletions players/cautiousplayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ private function missingPieces($line) {
throw new IllegalArgumentException("This line does not have a shared property ($line).");
}
$missing = [];
if (get_class($sharedProperty) === Shape) {
if (get_class($sharedProperty) === 'Shape') {
foreach (Color::colors() as $color) {
$tile = Tile::get($color, $sharedProperty);
if (!$line->contains($tile)) {
$missing[] = $tile;
}
}
} elseif (get_class($sharedProperty) === Color) {
} elseif (get_class($sharedProperty) === 'Color') {
foreach (Shape::shapes() as $shape) {
$tile = Tile::get($sharedProperty, $shape);
if (!$line->contains($tile)) {
Expand Down
2 changes: 1 addition & 1 deletion scores.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Scores {
private $scores = [];

public function __construct(array $players) {
Assert::type($players, Player);
Assert::type($players, 'Player');
foreach ($players as $player) {
$this->scores[] = new Score($player, 0);
}
Expand Down
1 change: 1 addition & 0 deletions tiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function sharedProperty() {

public function sharedProperties() {
$sharedProperty = null;
$sharedProperties = [];
foreach (Color::colors() as $color) {
foreach ($this->tiles() as $tile) {
if ($sharedProperty === null || $sharedProperty === $tile->color()) {
Expand Down

0 comments on commit 369dd8b

Please sign in to comment.