summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 21:58:23 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 21:58:23 +0200
commit11570d3e87707396674bdf5179df48c641bb154d (patch)
tree5c4677689569dbece70de222d1869b4049698f6d
parentcfc0341c66e5c24ee4c1b8a8e53afac99587244b (diff)
parent142ff436282844677b8b4e7d8ececd44440ec96d (diff)
downloadgigologadmin-11570d3e87707396674bdf5179df48c641bb154d.tar.gz
gigologadmin-11570d3e87707396674bdf5179df48c641bb154d.tar.bz2
gigologadmin-11570d3e87707396674bdf5179df48c641bb154d.zip
Tried to fix the psalm local changes done when I manually installed it
-rw-r--r--composer.json5
-rw-r--r--composer.lock194
-rw-r--r--generate-sample-gig-data.php62
-rw-r--r--giglogadmin.php20
-rw-r--r--includes/admin/helpfiles/instr_photog.php2
-rw-r--r--includes/admin/helpfiles/instr_reviewers.php2
-rw-r--r--includes/admin/helpfiles/instrunctions.php2
-rw-r--r--includes/admin/register_db_tables.php5
-rw-r--r--includes/admin/views/giglog_admin_page.php48
-rw-r--r--includes/admin/views/giglog_import_gigs.php40
-rw-r--r--includes/band.php11
-rw-r--r--includes/concert.php53
-rw-r--r--includes/concertlogs.php4
-rw-r--r--includes/public/shortcodes/giglog_bands.php4
-rw-r--r--includes/public/shortcodes/giglog_display_unprocessed.php6
-rw-r--r--includes/public/shortcodes/giglog_photographers.php16
-rw-r--r--includes/public/shortcodes/giglog_process_files.php2
-rw-r--r--includes/venue.php40
-rw-r--r--psalm.xml25
-rw-r--r--tests/ConcertTest.php21
20 files changed, 455 insertions, 107 deletions
diff --git a/composer.json b/composer.json
index dc24dda..5b0f97d 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,12 @@
],
"require-dev": {
"wp-phpunit/wp-phpunit": "^5.7",
+<<<<<<< HEAD
"vimeo/psalm": "^4.7"
+=======
+ "vimeo/psalm": "^4.7",
+ "humanmade/psalm-plugin-wordpress": "^2.0"
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
},
"scripts": {
"test": "npm run wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/giglogadmin/phpunit.xml'"
diff --git a/composer.lock b/composer.lock
index fefdd10..559c225 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,11 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
+<<<<<<< HEAD
"content-hash": "d330d5838bd28a6e9b15fe464962953a",
+=======
+ "content-hash": "da8593c79fc71116e3079512611bb8ec",
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
"packages": [],
"packages-dev": [
{
@@ -329,6 +333,7 @@
},
{
"name": "composer/xdebug-handler",
+<<<<<<< HEAD
"version": "2.0.1",
"source": {
"type": "git",
@@ -339,6 +344,18 @@
"type": "zip",
"url": "https://api.github.com/repos/composer/xdebug-handler/zipball/964adcdd3a28bf9ed5d9ac6450064e0d71ed7496",
"reference": "964adcdd3a28bf9ed5d9ac6450064e0d71ed7496",
+=======
+ "version": "2.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/composer/xdebug-handler.git",
+ "reference": "31d57697eb1971712a08031cfaff5a846d10bdf5"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/31d57697eb1971712a08031cfaff5a846d10bdf5",
+ "reference": "31d57697eb1971712a08031cfaff5a846d10bdf5",
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
"shasum": ""
},
"require": {
@@ -373,7 +390,11 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/xdebug-handler/issues",
+<<<<<<< HEAD
"source": "https://github.com/composer/xdebug-handler/tree/2.0.1"
+=======
+ "source": "https://github.com/composer/xdebug-handler/tree/2.0.0"
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
},
"funding": [
{
@@ -389,7 +410,11 @@
"type": "tidelift"
}
],
+<<<<<<< HEAD
"time": "2021-05-05T19:37:51+00:00"
+=======
+ "time": "2021-04-09T19:40:06+00:00"
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
},
{
"name": "dnoegel/php-xdg-base-dir",
@@ -530,6 +555,128 @@
"time": "2021-02-22T14:02:09+00:00"
},
{
+<<<<<<< HEAD
+=======
+ "name": "humanmade/psalm-plugin-wordpress",
+ "version": "2.0.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/humanmade/psalm-plugin-wordpress.git",
+ "reference": "c15b5d5159ef879f0707c33cc9a3fe993618edd1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/humanmade/psalm-plugin-wordpress/zipball/c15b5d5159ef879f0707c33cc9a3fe993618edd1",
+ "reference": "c15b5d5159ef879f0707c33cc9a3fe993618edd1",
+ "shasum": ""
+ },
+ "require": {
+ "johnbillion/wp-hooks": "^0.4.4",
+ "php-stubs/wordpress-stubs": "^5.5",
+ "vimeo/psalm": "^4"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.0"
+ },
+ "type": "psalm-plugin",
+ "extra": {
+ "psalm": {
+ "pluginClass": "PsalmWordPress\\Plugin"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "PsalmWordPress\\": [
+ "."
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Joe Hoyle",
+ "email": "joehoyle@gmail.com"
+ }
+ ],
+ "description": "WordPress stubs and plugin for Psalm.",
+ "support": {
+ "issues": "https://github.com/humanmade/psalm-plugin-wordpress/issues",
+ "source": "https://github.com/humanmade/psalm-plugin-wordpress/tree/2.0.4"
+ },
+ "time": "2021-03-10T12:17:03+00:00"
+ },
+ {
+ "name": "johnbillion/wp-hooks",
+ "version": "0.4.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/johnbillion/wp-hooks.git",
+ "reference": "eb9d32917bb5a0a10a3fc9bedbb3f509f885b769"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/johnbillion/wp-hooks/zipball/eb9d32917bb5a0a10a3fc9bedbb3f509f885b769",
+ "reference": "eb9d32917bb5a0a10a3fc9bedbb3f509f885b769",
+ "shasum": ""
+ },
+ "require-dev": {
+ "johnbillion/wp-hooks-generator": "~0.5.0",
+ "oomphinc/composer-installers-extender": "^1.1",
+ "roots/wordpress": "dev-nightly"
+ },
+ "type": "library",
+ "extra": {
+ "wordpress-install-dir": "vendor/wordpress/wordpress",
+ "wp-hooks": {
+ "ignore-files": [
+ "wp-admin/includes/deprecated.php",
+ "wp-admin/includes/ms-deprecated.php",
+ "wp-content/",
+ "wp-includes/deprecated.php",
+ "wp-includes/ID3/",
+ "wp-includes/IXR/",
+ "wp-includes/ms-deprecated.php",
+ "wp-includes/pomo/",
+ "wp-includes/random_compat/",
+ "wp-includes/Requests/",
+ "wp-includes/SimplePie/",
+ "wp-includes/sodium_compat/",
+ "wp-includes/Text/"
+ ],
+ "ignore-hooks": [
+ "load-categories.php",
+ "load-edit-link-categories.php",
+ "load-edit-tags.php",
+ "load-page-new.php",
+ "load-page.php",
+ "option_enable_xmlrpc",
+ "pre_option_enable_xmlrpc",
+ "{$tag}"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "GPL-3.0-or-later"
+ ],
+ "authors": [
+ {
+ "name": "John Blackbourn",
+ "homepage": "https://johnblackbourn.com/"
+ }
+ ],
+ "description": "All the actions and filters from WordPress core in machine-readable JSON format.",
+ "support": {
+ "issues": "https://github.com/johnbillion/wp-hooks/issues",
+ "source": "https://github.com/johnbillion/wp-hooks/tree/0.4.4"
+ },
+ "time": "2020-08-29T20:58:28+00:00"
+ },
+ {
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
"name": "netresearch/jsonmapper",
"version": "v2.1.0",
"source": {
@@ -690,6 +837,53 @@
"time": "2019-03-29T20:06:56+00:00"
},
{
+<<<<<<< HEAD
+=======
+ "name": "php-stubs/wordpress-stubs",
+ "version": "v5.7.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-stubs/wordpress-stubs.git",
+ "reference": "69baf30e7c92f149526da950a68222af05f7bc67"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/69baf30e7c92f149526da950a68222af05f7bc67",
+ "reference": "69baf30e7c92f149526da950a68222af05f7bc67",
+ "shasum": ""
+ },
+ "replace": {
+ "giacocorsiglia/wordpress-stubs": "*"
+ },
+ "require-dev": {
+ "giacocorsiglia/stubs-generator": "^0.5.0",
+ "php": "~7.1"
+ },
+ "suggest": {
+ "paragonie/sodium_compat": "Pure PHP implementation of libsodium",
+ "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
+ "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan"
+ },
+ "type": "library",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "WordPress function and class declaration stubs for static analysis.",
+ "homepage": "https://github.com/php-stubs/wordpress-stubs",
+ "keywords": [
+ "PHPStan",
+ "static analysis",
+ "wordpress"
+ ],
+ "support": {
+ "issues": "https://github.com/php-stubs/wordpress-stubs/issues",
+ "source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.7.0"
+ },
+ "time": "2021-03-10T10:29:23+00:00"
+ },
+ {
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
"source": {
diff --git a/generate-sample-gig-data.php b/generate-sample-gig-data.php
index 26ba0cf..11e9a0a 100644
--- a/generate-sample-gig-data.php
+++ b/generate-sample-gig-data.php
@@ -7,9 +7,9 @@
abstract class GeneratorBase
{
- abstract public function get();
+ abstract public function get() : string;
- function pick($arr)
+ function pick(array $arr) : string
{
return $arr[array_rand($arr)];
}
@@ -17,13 +17,23 @@ abstract class GeneratorBase
class BandNameGenerator extends GeneratorBase
{
- private $prefixes = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string}
+ */
+ private array $prefixes = array(
"",
"a",
"the",
);
- private $adverbs = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string, 4: string, 5: string, 6: string, 7: string}
+ */
+ private array $adverbs = array(
"bestial",
"dead",
"incongruent",
@@ -34,7 +44,12 @@ class BandNameGenerator extends GeneratorBase
"flamboyant",
);
- private $verbs = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string, 4: string, 5: string, 6: string}
+ */
+ private array $verbs = array(
"kill",
"regurgitat",
"destroy",
@@ -44,14 +59,19 @@ class BandNameGenerator extends GeneratorBase
"mutilat",
);
- private $endings = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string}
+ */
+ private array $endings = array(
"er",
"ers",
"ing",
"ed",
);
- public function get()
+ public function get() : string
{
$parts = array(
$this->pick($this->prefixes),
@@ -64,7 +84,12 @@ class BandNameGenerator extends GeneratorBase
class VenueGenerator extends GeneratorBase
{
- private $prefix1 = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string, 4: string}
+ */
+ private array $prefix1 = array(
"",
"royal",
"shabby",
@@ -72,7 +97,12 @@ class VenueGenerator extends GeneratorBase
"drunken",
);
- private $prefix2 = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string, 4: string, 5: string}
+ */
+ private array $prefix2 = array(
"",
"music",
"fiddler",
@@ -81,7 +111,12 @@ class VenueGenerator extends GeneratorBase
"mental",
);
- private $type = array(
+ /**
+ * @var string[]
+ *
+ * @psalm-var array{0: string, 1: string, 2: string, 3: string, 4: string, 5: string, 6: string}
+ */
+ private array $type = array(
"hall",
"museum",
"asylum",
@@ -91,7 +126,7 @@ class VenueGenerator extends GeneratorBase
"lighthouse"
);
- public function get()
+ public function get() : string
{
$parts = array(
$this->pick($this->prefix1),
@@ -104,7 +139,10 @@ class VenueGenerator extends GeneratorBase
class LinkGenerator extends GeneratorBase
{
- public function get()
+ /**
+ * @return string
+ */
+ public function get() : string
{
return 'https://example.com/' . bin2hex(random_bytes(8));
}
diff --git a/giglogadmin.php b/giglogadmin.php
index 0e8b399..c8ae9b0 100644
--- a/giglogadmin.php
+++ b/giglogadmin.php
@@ -36,7 +36,7 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
class GiglogAdmin_Plugin
{
- static public function init() {
+ static public function init(): void {
add_shortcode('giglog_cities', 'giglogadmin_getfilters');
add_shortcode('giglog_bands', 'giglogadmin_getconcerts');
add_shortcode('giglog_unprocessed', 'giglogadmin_display_unprocessed');
@@ -49,18 +49,20 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
add_filter( 'wp_nav_menu_args', array( 'GiglogAdmin_Plugin', 'nav_menu_args' ));
}
- static function activate() {
+ static function activate(): void {
require_once __DIR__ . '/includes/admin/register_db_tables.php';
}
- static function deactivate() {
+ static function deactivate(): void {
}
/**
* Adds the 'Giglog' top level menu to the left side WordPress admin
* menu. Other subpages will come later.
+ *
+ * @return void
*/
- static function add_admin_pages() {
+ static function add_admin_pages(): void {
$top = add_menu_page(
"Giglog admin", // Page title
"Giglog", // Menu title
@@ -80,13 +82,17 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
"giglog_import", // menu slug
array( 'GiglogAdmin_ImportGigsPage', 'render_html' )); // callable
- add_action( 'load-' . $import_hook, array( 'GiglogAdmin_ImportGigsPage', 'submit_form' ) );
+ if ($import_hook !== false) {
+ add_action(
+ 'load-' . $import_hook,
+ array( 'GiglogAdmin_ImportGigsPage', 'submit_form' ) );
+ }
wp_register_style( 'css_style', plugins_url( '/includes/css/main.css', __FILE__ ) );
wp_enqueue_style('css_style');
}
- static function add_help_pages() {
+ static function add_help_pages(): void {
add_menu_page(
"Help for ET users", // Page title
"Help for ET users", // Menu title
@@ -119,7 +125,7 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) {
* Giglog admin pages should only be visible for logged in users/can eventually
* be customized by role if needed
*/
- static function nav_menu_args( $args = '' ) {
+ static function nav_menu_args( array $args = [] ) : array {
if ( is_user_logged_in() ) {
$args['menu'] = 'Loggedusers';
} else {
diff --git a/includes/admin/helpfiles/instr_photog.php b/includes/admin/helpfiles/instr_photog.php
index 0750557..f661c5f 100644
--- a/includes/admin/helpfiles/instr_photog.php
+++ b/includes/admin/helpfiles/instr_photog.php
@@ -13,7 +13,7 @@ if ( !class_exists( 'Instructions_Photogs' ) ) {
- static function render_instr_photo_html() {
+ static function render_instr_photo_html(): void {
diff --git a/includes/admin/helpfiles/instr_reviewers.php b/includes/admin/helpfiles/instr_reviewers.php
index e00a432..3632980 100644
--- a/includes/admin/helpfiles/instr_reviewers.php
+++ b/includes/admin/helpfiles/instr_reviewers.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Reviewers' ) ) {
class Instructions_Reviewers {
- static function render_instr_rev_html() {
+ static function render_instr_rev_html(): void {
?>
diff --git a/includes/admin/helpfiles/instrunctions.php b/includes/admin/helpfiles/instrunctions.php
index 49b77fe..b9c4d89 100644
--- a/includes/admin/helpfiles/instrunctions.php
+++ b/includes/admin/helpfiles/instrunctions.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Page' ) ) {
class Instructions_Page {
- static function render_instr_html() {
+ static function render_instr_html(): void {
?>
diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php
index 947be22..11223b3 100644
--- a/includes/admin/register_db_tables.php
+++ b/includes/admin/register_db_tables.php
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
if (!function_exists('giglogadmin_populate_countries')) {
- function giglogadmin_populate_countries()
+ function giglogadmin_populate_countries(): void
{
global $wpdb;
$wpdb->query(
@@ -254,6 +254,9 @@ if (!function_exists('giglogadmin_populate_countries')) {
if ( !function_exists( "giglog_register_db_tables") )
{
+ /**
+ * @return void
+ */
function giglog_register_db_tables()
{
$db_version = get_option('giglogadmin_db_version');
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 3482ae2..9d9d759 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
require_once __DIR__ . '/../../venue.php';
class GiglogAdmin_AdminPage {
- static function render_html() {
+ static function render_html(): void {
?>
<div class="wrap">
<h1>Giglog Admin</h1>
@@ -36,13 +36,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo?
}
- static function get_allvenues($invenue)
+ static function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string
{
$select = '<select name="selectvenueadmin">';
$select .= '<option value="">Please Select..</option>';
foreach ( GiglogAdmin_Venue::all_venues() AS $venue ) {
- if($invenue==$venue ->id() ) $select .= '<option value="' . $venue -> id(). '" selected="selected">'.$venue->name();
- else $select .= '<option value="' . $venue->id() . '">'. $venue->name();
+ if($invenue && $invenue->id() == $venue->id() ) {
+ $select .= '<option value="' . $venue->id(). '" selected="selected">'.$venue->name();
+ }
+ else {
+ $select .= '<option value="' . $venue->id() . '">'. $venue->name();
+ }
$select .='</option>';
}
$select .= '</select>';
@@ -50,7 +54,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_user($cid, $ctype)
+ static function get_user( ?int $cid, string $ctype): string
{
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
@@ -75,7 +79,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_filters()
+ static function get_filters(): string
{
$cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities());
$cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS );
@@ -107,9 +111,9 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
|| $venue_list[0];
$select .= '<select name="selectvenue">';
- foreach ( $venue_list AS $venue ) {
- //below line returns an erorr which I haven't really figured out yet But filtering works. It doesn't keep the venue selected in the dropdown
- $select .= '<option value="' . $venue[0] . '"' . selected($venue[0], $selected_venue) . '>';
+
+ foreach ( $venue_list as $venue ) {
+ $select .= '<option value="' . $venue[0] . '"' . selected($venue, $selected_venue) . '>';
$select .= $venue[1] . '</option>';
}
$select .= '</select>';
@@ -125,13 +129,13 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $select;
}
- static function editforms()
+ static function editforms(): string
{
$cid = filter_input(INPUT_POST, "cid");
$editing = filter_input(INPUT_POST, "edit") == "EDIT";
if ($editing && !empty($cid)) //A bit overdoing with the checks if concert ID is empty both here and in find_cid. But based on that, things are NULL or not. Better ideas?
- $c = GiglogAdmin_Concert::find_cid($cid);
+ $c = GiglogAdmin_Concert::get($cid);
else
$c = new GiglogAdmin_Concert();
@@ -140,7 +144,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
.'<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>'
.'<input type="hidden" name="pid" value="' .$c->id(). '" />'
.'<label for="cname">Concert Name:</label><textarea id="cname" name="cname" value="'.$c->cname().'">'.$c->cname().'</textarea><br>'
- .'<label for="venue">Venue:</label>'.GiglogAdmin_AdminPage::get_allvenues($c->venue()).'<br>'
+ .'<label for="venue">Venue:</label>' . GiglogAdmin_AdminPage::get_venue_selector($c->venue()) . '<br>'
.'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>'
.'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>'
.'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>'
@@ -168,7 +172,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $content;
}
- static function adminactions($concert_id)
+ static function adminactions( int $concert_id ) : string
{
global $wpdb;
$query = "SELECT id,wpgs_name from wpg_pressstatus" ;
@@ -193,7 +197,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
//function to calculate if the concert has been added in the past 10 days or before that and show a green NEW for the newest rows
- static function getpublishstatus($concert_id)
+ /**
+ * @return null|string
+ */
+ static function getpublishstatus(int $concert_id)
{
global $wpdb;
$date1 = new DateTime("now");
@@ -210,11 +217,11 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_concerts()
+ static function get_concerts(): string
{
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
- $roles = ( array ) $hf_user->roles;
+ $roles = $hf_user->roles;
global $wpdb;
$content = '<table class="assignit">';
@@ -293,6 +300,9 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
+ /**
+ * @return void
+ */
static function update()
{
global $wpdb;
@@ -372,7 +382,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
}
- static function assignconcert($p1, $c)
+ static function assignconcert($p1, $c): void
{
global $wpdb;
@@ -393,7 +403,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
wp_mail( $to, $subject, $body, $headers );
}
- static function unassignconcert($p1, $c)
+ static function unassignconcert($p1, $c): void
{
global $wpdb;
@@ -414,7 +424,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
wp_mail( $to, $subject, $body, $headers );
}
- static function returnuser($p1, $c)
+ static function returnuser(string $p1, ?int $c): string
{
global $wpdb;
$hf_user = wp_get_current_user();
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 053f505..a8daa3f 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -12,7 +12,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
require_once __DIR__ . '/../../venue.php';
class GiglogAdmin_ImportGigsPage {
- static function render_html() {
+ static function render_html(): void {
?>
<div class="wrap">
<h1>Import gigs</h1>
@@ -27,7 +27,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
<?php
}
- static function submit_form() {
+ static function submit_form(): void {
if ('POST' === $_SERVER['REQUEST_METHOD'] && current_user_can('upload_files') && !empty($_FILES['giglog_import_file']['tmp_name'])) {
$nonce = $_POST['giglog_import_nonce'];
$valid_nonce = isset($nonce) && wp_verify_nonce($nonce);
@@ -42,14 +42,18 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
* tab character:
*
* 1. Concertname
- * 2. Venuename
+ * 2. Venuename or numeric venue id
* 3. Concert date
* 4. Ticket link
* 5. Event info link
*
* Empty lines are ignored.
+ *
+ * @return void
+ *
+ * @param ArrayAccess|array $file
*/
- static function process_upload($file) {
+ static function process_upload(array $file): void {
$newconcert= [];
$fo = new SplFileObject($file['tmp_name']);
@@ -61,31 +65,21 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
}
$resultArray = explode("\t", $line);
- $cname = trim($resultArray[0]);
+ $cname = trim($resultArray[0]);
$venue = trim($resultArray[1]);
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = trim($resultArray[3]);
- $eventlink = trim($resultArray[4]);
- //first item in the row should be concert name $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2];
- //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4];
-
-
- if (is_numeric($venue))
- $newconcert[1] = $venue;
+ if (is_numeric($venue)) {
+ $venue = GiglogAdmin_Venue::get($venue);
+ }
else {
- $v = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); //phase 666 of the project should maybe consider both city and band country when creating concerts/importing files
- $newconcert[1] = $v->id();
+ $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
}
- //not sure how to check dates, hopefully manual verification of files will take care of it
+ $condate = date('Y-m-d', strtotime($resultArray[2]));
+ $ticketlink = trim($resultArray[3]);
+ $eventlink = trim($resultArray[4]);
- GiglogAdmin_Concert::create(
- $cname,
- $newconcert[1],
- $condate,
- $ticketlink,
- $eventlink);
+ GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
}
}
}
diff --git a/includes/band.php b/includes/band.php
index 14daa18..3460acb 100644
--- a/includes/band.php
+++ b/includes/band.php
@@ -25,7 +25,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
$this->country = isset($attrs->wpgband_country) ? $attrs->wpgband_country : 'NO';
}
- static function create($bandname, $country = 'NO')
+ static function create($bandname, $country = 'NO'): self
{
$band = GiglogAdmin_Band::find($bandname, $country);
@@ -46,7 +46,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return $band;
}
- static function find($name, $country)
+ static function find($name, $country): ?self
{
global $wpdb;
@@ -83,6 +83,11 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($results);
}
+ /**
+ * @return array|string
+ *
+ * @psalm-return array{0: mixed, 1: mixed}|string
+ */
static function get_band($bid)
{
global $wpdb;
@@ -116,7 +121,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($wpdb->last_error);
}
- public function save()
+ public function save(): void
{
global $wpdb;
diff --git a/includes/concert.php b/includes/concert.php
index d95934e..e3c32e8 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -25,33 +25,49 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
{
$this->id = isset($attrs->id) ? $attrs->id : NULL;
$this->cname = isset($attrs->wpgconcert_name) ? $attrs->wpgconcert_name : NULL;
- $this->venue = isset($attrs->venue) ? $attrs->venue : NULL;
$this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL;
$this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL;
$this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL;
+
+
+ if ( isset( $attrs->venue ) ) {
+ if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) {
+ $venue_attrs = (object) [
+ "id" => $attrs->venue,
+ "wpgvenue_name" => $attrs->wpgvenue_name,
+ "wpgvenue_city" => $attrs->wpgvenue_city,
+ ];
+
+ $this->venue = new GiglogAdmin_Venue($venue_attrs);
+ }
+ else {
+ $this->venue = GiglogAdmin_Venue::get($attrs->venue);
+ }
+ }
}
- static function find_cid($id)
+ /**
+ * Get concert with given id.
+ *
+ * @param int $id.
+ * @return null|self.
+ */
+ static function get( int $id ) : ?self
{
global $wpdb;
- if(!empty($id))
- {
- $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"';
- $results = $wpdb->get_results($csql);
- if ($results)
- {
- return new GiglogAdmin_Concert($results[0]);
- }
- }
- else
- {
- return new GiglogAdmin_Concert();
- }
+ $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city '
+ . 'FROM wpg_concerts '
+ . 'LEFT JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '
+ . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id);
+
+ $results = $wpdb->get_results($query);
+
+ return $results ? new GiglogAdmin_Concert($results[0]) : NULL;
}
- public static function create($name, $venue, $date, $ticketlink, $eventlink)
+ public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self
{
if ( GiglogAdmin_Concert::find($name, $venue, $date) ) {
error_log( 'DUPLICATE ROW detected: '
@@ -151,18 +167,17 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
. ' and venue = ' . $venue
. ' and wpgconcert_date ="' . $date . '"';
- error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}");
return $wpdb->get_results($sql);
}
- public function save()
+ public function save(): void
{
global $wpdb;
$wpdb->insert('wpg_concerts', array(
'id' => '',
'wpgconcert_name' => $this->cname,
- 'venue' => $this->venue,
+ 'venue' => $this->venue->id(),
'wpgconcert_date' => $this->cdate,
'wpgconcert_tickets' => $this->tickets,
'wpgconcert_event' => $this->eventlink
diff --git a/includes/concertlogs.php b/includes/concertlogs.php
index 409a454..3b8083a 100644
--- a/includes/concertlogs.php
+++ b/includes/concertlogs.php
@@ -12,8 +12,10 @@ if ( !class_exists( 'GiglogAdmin_Concertlogs' ) )
/**
* Adds a default entry for the given concert id in the
* concert logs table.
+ *
+ * @return void
*/
- public static function add($concert_id)
+ public static function add($concert_id): void
{
global $wpdb;
diff --git a/includes/public/shortcodes/giglog_bands.php b/includes/public/shortcodes/giglog_bands.php
index 78fd72b..e4fe71d 100644
--- a/includes/public/shortcodes/giglog_bands.php
+++ b/includes/public/shortcodes/giglog_bands.php
@@ -10,7 +10,7 @@
* builds the table with concerts
*/
-function giglogadmin_getfilters()
+function giglogadmin_getfilters(): string
{
global $wpdb;
@@ -59,7 +59,7 @@ function giglogadmin_getfilters()
}
-function giglogadmin_getconcerts()
+function giglogadmin_getconcerts(): string
{
global $wpdb;
// Shortcodes RETURN content, so store in a variable to return
diff --git a/includes/public/shortcodes/giglog_display_unprocessed.php b/includes/public/shortcodes/giglog_display_unprocessed.php
index aa3596c..90ef69f 100644
--- a/includes/public/shortcodes/giglog_display_unprocessed.php
+++ b/includes/public/shortcodes/giglog_display_unprocessed.php
@@ -16,7 +16,7 @@
* gone through the processing process - aka fetching each line and
* transforming it into a concert line
*/
-function giglogadmin_getunprocessed()
+function giglogadmin_getunprocessed(): string
{
global $wpdb;
@@ -42,7 +42,7 @@ function giglogadmin_getunprocessed()
* venue exists. If they don't, they get created, if they do, their ID from
* their table is fetchd and used in concerts table
*/
-function giglogadmin_insertconcerts()
+function giglogadmin_insertconcerts(): string
{
global $wpdb;
$concertlist = '<p>Inserted the following:</p>';
@@ -128,7 +128,7 @@ function giglogadmin_insertconcerts()
return $concertlist;
}
-function giglogadmin_display_unprocessed() {
+function giglogadmin_display_unprocessed(): string {
$output = giglogadmin_getunprocessed();
$output .= '<form method="POST" action=""><input type="submit" name="ProcessConcerts" value="ProcessConcerts"/></form>';
diff --git a/includes/public/shortcodes/giglog_photographers.php b/includes/public/shortcodes/giglog_photographers.php
index 500445a..829c53e 100644
--- a/includes/public/shortcodes/giglog_photographers.php
+++ b/includes/public/shortcodes/giglog_photographers.php
@@ -10,7 +10,7 @@
* Admin users also control concert statuses here
*/
-function giglogadmin_assignconcert($p1, $c)
+function giglogadmin_assignconcert($p1, $c): void
{
global $wpdb;
@@ -40,7 +40,7 @@ function giglogadmin_assignconcert($p1, $c)
}
-function giglogadmin_unassignconcert($p1, $c)
+function giglogadmin_unassignconcert($p1, $c): void
{
global $wpdb;
@@ -71,6 +71,9 @@ function giglogadmin_unassignconcert($p1, $c)
}
+/**
+ * @return null|string
+ */
function giglogadmin_getpublishstatus ($c)
{
global $wpdb;
@@ -88,6 +91,9 @@ function giglogadmin_getpublishstatus ($c)
}
+/**
+ * @return null|string
+ */
function giglogadmin_returnuser($p1, $c)
{
global $wpdb;
@@ -164,7 +170,7 @@ function giglogadmin_returnuser($p1, $c)
}
-function giglogadmin_getfiltersphotog() {
+function giglogadmin_getfiltersphotog(): string {
global $wpdb;
//echo (var_dump($_POST["selectvenue"]));
@@ -211,7 +217,7 @@ function giglogadmin_getfiltersphotog() {
}
-function giglogadmin_getconcertsphotog ( ) {
+function giglogadmin_getconcertsphotog ( ): string {
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
$roles = ( array ) $hf_user->roles;
@@ -370,7 +376,7 @@ function giglogadmin_getconcertsphotog ( ) {
return $content;
}
-function giglogadmin_photographers()
+function giglogadmin_photographers(): string
{
$output = giglogadmin_getfiltersphotog();
$output .= giglogadmin_getconcertsphotog();
diff --git a/includes/public/shortcodes/giglog_process_files.php b/includes/public/shortcodes/giglog_process_files.php
index 9dc2ec0..9443cda 100644
--- a/includes/public/shortcodes/giglog_process_files.php
+++ b/includes/public/shortcodes/giglog_process_files.php
@@ -9,7 +9,7 @@
* Band Venue Date TicketLink Eventlink. The form is at the end of this snippet
*/
-function giglogadmin_upload_files() {
+function giglogadmin_upload_files(): string {
global $wpdb;
$output = "";
$dir = wp_upload_dir()['basedir'].'/concertlists/'; //the basedir is from file uploader plugin, namely the uploads folder in which I created a concertlist folder
diff --git a/includes/venue.php b/includes/venue.php
index f6f46b2..f9f7e4f 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -19,7 +19,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
* so this constructor can be used to construct the object
* directly from the database row.
*/
- private function __construct($attrs)
+ public function __construct($attrs)
{
$this->id = isset($attrs->id) ? $attrs->id : NULL;
$this->name = isset($attrs->wpgvenue_name) ? $attrs->wpgvenue_name : NULL;
@@ -28,7 +28,23 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
$this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL;
}
- static function create($name, $city = 'Oslo')
+ /**
+ * Get venue by given id.
+ *
+ * @param int $id.
+ * @return null|self.
+ */
+ static function get(int $id) : ?self
+ {
+ global $wpdb;
+
+ $query = $wpdb->prepare('SELECT * from wpg_venues WHERE id = %d', $id);
+ $results = $wpdb->get_results($query);
+
+ return $results ? new GiglogAdmin_Venue($results[0]) : NULL;
+ }
+
+ static function create($name, $city = 'Oslo'): self
{
$venue = new GiglogAdmin_Venue((object) [
'wpgvenue_name' => $name,
@@ -43,7 +59,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return $venue;
}
- static function find_or_create($name, $city = 'Oslo')
+ static function find_or_create(string $name, string $city = 'Oslo'): self
{
global $wpdb;
$venuesql = 'SELECT * FROM wpg_venues WHERE upper(wpgvenue_name)=upper("' . $name . '")'.' and wpgvenue_city="'.$city.'"';
@@ -61,7 +77,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
}
}
- static function all_cities()
+ static function all_cities(): array
{
global $wpdb;
$results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues');
@@ -69,7 +85,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return array_map(function ($r) { return $r->wpgvenue_city; }, $results);
}
- static function all_venues()
+ /**
+ * @return self[]
+ *
+ * @psalm-return array<array-key, self>
+ */
+ static function all_venues(): array
{
global $wpdb;
@@ -79,7 +100,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
}
- static function venues_in_city($city)
+ /**
+ * @return self[]
+ *
+ * @psalm-return array<array-key, self>
+ */
+ static function venues_in_city(string $city): array
{
global $wpdb;
$q = $wpdb->prepare(
@@ -89,7 +115,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results);
}
- public function save()
+ public function save(): void
{
global $wpdb;
diff --git a/psalm.xml b/psalm.xml
index 8abd320..5cf23eb 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,4 +1,13 @@
<?xml version="1.0"?>
+<<<<<<< HEAD
+=======
+<!--
+SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+
+SPDX-License-Identifier: CC0-1.0
+-->
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
<psalm
errorLevel="4"
resolveFromConfigFile="true"
@@ -7,6 +16,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
+<<<<<<< HEAD
<file name="generate-sample-gig-data.php" />
<file name="giglogadmin.php" />
<file name="includes/band.php" />
@@ -33,3 +43,18 @@
</ignoreFiles>
</projectFiles>
</psalm>
+=======
+ <file name="generate-sample-gig-data.php"/>
+ <file name="giglogadmin.php"/>
+ <directory name="includes"/>
+ <ignoreFiles>
+ <directory name="vendor"/>
+ <directory name="includes/public/shortcodes" />
+ </ignoreFiles>
+ </projectFiles>
+
+ <issueHandlers>
+ <InvalidGlobal errorLevel="suppress" />
+ </issueHandlers>
+<plugins><pluginClass class="PsalmWordPress\Plugin"/></plugins></psalm>
+>>>>>>> 142ff436282844677b8b4e7d8ececd44440ec96d
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
index 6d14b68..0517ad8 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -19,7 +19,7 @@ final class ConcertTest extends WP_UnitTestCase
"https://example.com/events/93");
$this->assertEquals("a concert", $concert->cname());
- $this->assertEquals($venue->id(), $concert->venue());
+ $this->assertEquals($venue->id(), $concert->venue()->id());
$this->assertEquals($today, $concert->cdate());
$this->assertEquals("https://example.com/tickets/42", $concert->tickets());
$this->assertEquals("https://example.com/events/93", $concert->eventlink());
@@ -68,4 +68,23 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertNull($new);
}
+
+ public function testGetConcertByIdReturnsFullConcertObject() : void
+ {
+ $venue = GiglogAdmin_Venue::create("a venue");
+ $today = date("Y-m-d");
+
+ $gig = GiglogAdmin_Concert::create(
+ "a concert123",
+ $venue->id(),
+ $today,
+ "https://example.com/tickets/42",
+ "https://example.com/events/93");
+
+ $fetched_gig = GiglogAdmin_Concert::get($gig->id());
+
+ $this->assertEquals($gig->id(), $fetched_gig->id());
+ $this->assertEquals($gig->cname(), $fetched_gig->cname());
+ $this->assertEquals($venue->id(), $fetched_gig->venue()->id());
+ }
}