From ecd1eb7848d7657267a55cbee03eb2f90a1ba1b7 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 2 Sep 2021 08:54:58 +0200 Subject: psalm: Ad types to attrs and constructor for Venue --- includes/venue.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'includes/venue.php') diff --git a/includes/venue.php b/includes/venue.php index aedb6a7..6de14c6 100644 --- a/includes/venue.php +++ b/includes/venue.php @@ -7,11 +7,11 @@ if ( !class_exists('GiglogAdmin_Venue') ) { class GiglogAdmin_Venue { - private $id; - private $name; - private $city; - private $address; - private $webpage; + private int $id; + private string $name; + private string $city; + private string $address; + private string $webpage; /* * Constructs a new venue object from an array of attributes. @@ -19,7 +19,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) { * so this constructor can be used to construct the object * directly from the database row. */ - public function __construct($attrs) + public function __construct(object $attrs) { $this->id = isset($attrs->id) ? $attrs->id : NULL; $this->name = isset($attrs->wpgvenue_name) ? $attrs->wpgvenue_name : NULL; -- cgit v1.2.3 From 52980d074809a18d150a88313ab86054870c416e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 2 Sep 2021 09:20:44 +0200 Subject: Fix more type issues in Concert and Venue classes --- includes/venue.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'includes/venue.php') diff --git a/includes/venue.php b/includes/venue.php index 6de14c6..541680f 100644 --- a/includes/venue.php +++ b/includes/venue.php @@ -7,11 +7,11 @@ if ( !class_exists('GiglogAdmin_Venue') ) { class GiglogAdmin_Venue { - private int $id; - private string $name; - private string $city; - private string $address; - private string $webpage; + private ?int $id; + private ?string $name; + private ?string $city; + private ?string $address; + private ?string $webpage; /* * Constructs a new venue object from an array of attributes. -- cgit v1.2.3 From dbdcf4c486fb526861d040ed482d2dc4cdb06969 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 2 Sep 2021 09:52:38 +0200 Subject: Make name and city required attributes for Venues. It does not make sense to have anonymous venues nowhere. --- includes/venue.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'includes/venue.php') diff --git a/includes/venue.php b/includes/venue.php index 541680f..3ad0f06 100644 --- a/includes/venue.php +++ b/includes/venue.php @@ -8,8 +8,16 @@ if ( !class_exists('GiglogAdmin_Venue') ) { class GiglogAdmin_Venue { private ?int $id; - private ?string $name; - private ?string $city; + + /** + * @psalm-suppress PropertyNotSetInConstructor + */ + private string $name; + + /** + * @psalm-suppress PropertyNotSetInConstructor + */ + private string $city; private ?string $address; private ?string $webpage; @@ -22,8 +30,16 @@ if ( !class_exists('GiglogAdmin_Venue') ) { public function __construct(object $attrs) { $this->id = isset($attrs->id) ? $attrs->id : NULL; - $this->name = isset($attrs->wpgvenue_name) ? $attrs->wpgvenue_name : NULL; - $this->city = isset($attrs->wpgvenue_city) ? $attrs->wpgvenue_city : NULL; + + if (isset($attrs->wpgvenue_name, $attrs->wpgvenue_city)) { + $this->name = $attrs->wpgvenue_name; + $this->city = $attrs->wpgvenue_city; + } + else { + error_log('Trying to construct a Venue without a name or a city'); + wp_die(); + } + $this->address = isset($attrs->wpgvenue_address) ? $attrs->wpgvenue_address : NULL; $this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL; } @@ -108,8 +124,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) { static function venues_in_city(string $city): array { global $wpdb; - $q = $wpdb->prepare( - "select id, wpgvenue_name from wpg_venues where wpgvenue_city=%s", $city); + $q = $wpdb->prepare("select * from wpg_venues where wpgvenue_city=%s", $city); $results = $wpdb->get_results($q); return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results); -- cgit v1.2.3