From cd5255cbb83a52c96cdca4d68b20be8c8d245bea Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Thu, 23 May 2019 10:58:57 +0200 Subject: [PATCH] Minor code cleanup --- .tests/lib/UloggerAPITestCase.php | 4 ++-- .tests/tests/ImportTest.php | 7 ++++++- .tests/tests/InternalAPITest.php | 7 ++++++- .tests/tests/PositionTest.php | 2 +- composer.json | 5 +++-- helpers/auth.php | 7 +++++-- helpers/position.php | 4 +--- helpers/track.php | 5 ----- helpers/user.php | 2 -- scripts/import_cli.php | 4 ++-- utils/export.php | 1 - 11 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.tests/lib/UloggerAPITestCase.php b/.tests/lib/UloggerAPITestCase.php index c98334e..45eb67e 100644 --- a/.tests/lib/UloggerAPITestCase.php +++ b/.tests/lib/UloggerAPITestCase.php @@ -35,8 +35,8 @@ class UloggerAPITestCase extends BaseDatabaseTestCase { /** * Authenticate on server - * @param string $user Login - * + * @param string|null $user Login (defaults to test user) + * @param string|null $pass Optional password (defaults to test password) * @return bool true on success, false otherwise */ public function authenticate($user = NULL, $pass = NULL) { diff --git a/.tests/tests/ImportTest.php b/.tests/tests/ImportTest.php index 0febee2..a59a9f1 100644 --- a/.tests/tests/ImportTest.php +++ b/.tests/tests/ImportTest.php @@ -1,5 +1,7 @@ assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } - + /** + * @param ResponseInterface $response + * @return bool|SimpleXMLElement + */ private function getXMLfromResponse($response) { $xml = false; libxml_use_internal_errors(true); diff --git a/.tests/tests/InternalAPITest.php b/.tests/tests/InternalAPITest.php index 8828954..ea8f652 100644 --- a/.tests/tests/InternalAPITest.php +++ b/.tests/tests/InternalAPITest.php @@ -1,5 +1,7 @@ assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); } - + /** + * @param ResponseInterface $response + * @return bool|SimpleXMLElement + */ private function getXMLfromResponse($response) { $xml = false; libxml_use_internal_errors(true); diff --git a/.tests/tests/PositionTest.php b/.tests/tests/PositionTest.php index 72bf59f..98a6f0b 100644 --- a/.tests/tests/PositionTest.php +++ b/.tests/tests/PositionTest.php @@ -133,7 +133,7 @@ class PositionTest extends UloggerDatabaseTestCase { $this->assertEquals($trackId2, $position->trackId); break; default: - $this->assert("Unexpected position: {$position->id}"); + $this->assertTrue(false, "Unexpected position: {$position->id}"); } } } diff --git a/composer.json b/composer.json index 4561df0..292e2b0 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,9 @@ "ulrichsg/getopt-php": "^3.2", "ext-json": "*", "ext-pdo": "*", - "ext-xmlwriter": "*" + "ext-xmlwriter": "*", + "ext-simplexml": "*", + "ext-libxml": "*" }, "scripts": { "test": "./vendor/bin/phpunit" @@ -13,6 +15,5 @@ "vlucas/phpdotenv": "^3.3", "guzzlehttp/guzzle": "^6.3", "phpunit/dbunit": "^2.0" - } } diff --git a/helpers/auth.php b/helpers/auth.php index 056fac4..6206bd2 100644 --- a/helpers/auth.php +++ b/helpers/auth.php @@ -28,6 +28,7 @@ class uAuth { private $isAuthenticated = false; + /** @var null|uUser */ public $user = null; public function __construct() { @@ -105,9 +106,11 @@ } /** - * Process log in request + * Check valid pass for given login * - * @return void + * @param $login + * @param $pass + * @return boolean True if valid */ public function checkLogin($login, $pass) { if (!is_null($login) && !is_null($pass)) { diff --git a/helpers/position.php b/helpers/position.php index 887e39e..10e6cca 100644 --- a/helpers/position.php +++ b/helpers/position.php @@ -57,8 +57,6 @@ public $isValid = false; - private static $db; - /** * Constructor * @param integer $positionId Position id @@ -235,7 +233,7 @@ * * @param int $userId Optional limit to given user id * @param int $trackId Optional limit to given track id - * @return array|bool Array of uPosition positions, false on error + * @return uPosition[]|bool Array of uPosition positions, false on error */ public static function getAll($userId = NULL, $trackId = NULL) { $rules = []; diff --git a/helpers/track.php b/helpers/track.php index 3e7eacc..e2aecf2 100644 --- a/helpers/track.php +++ b/helpers/track.php @@ -31,11 +31,6 @@ public $isValid = false; - /** - * @var uDb $db - */ - private static $db = null; - /** * Constructor * diff --git a/helpers/user.php b/helpers/user.php index 7496829..1decc2a 100644 --- a/helpers/user.php +++ b/helpers/user.php @@ -34,8 +34,6 @@ public $isAdmin = false; public $isValid = false; - private static $db = null; - /** * Constructor * diff --git a/scripts/import_cli.php b/scripts/import_cli.php index cd811af..30ff49d 100644 --- a/scripts/import_cli.php +++ b/scripts/import_cli.php @@ -47,7 +47,7 @@ $getopt->addOptions([ Option::create('h', 'help') ->setDescription('Show usage/help'), - Option::create('u', 'user-id', \GetOpt\GetOpt::OPTIONAL_ARGUMENT) + Option::create('u', 'user-id', GetOpt::OPTIONAL_ARGUMENT) ->setDescription('Which user to import the track(s) for (default: 1)') ->setDefaultValue(1) ->setValidation('is_numeric', '%s has to be an integer'), @@ -60,7 +60,7 @@ $getopt->addOptions([ ]); $getopt->addOperand( - Operand::create('gpx', \GetOpt\Operand::MULTIPLE + \GetOpt\Operand::REQUIRED) + Operand::create('gpx', Operand::MULTIPLE + Operand::REQUIRED) ->setDescription('One or more GPX files to import') ->setValidation('is_readable', '%s: %s is not readable') ); diff --git a/utils/export.php b/utils/export.php index f5f1005..8154a2e 100644 --- a/utils/export.php +++ b/utils/export.php @@ -123,7 +123,6 @@ if ($trackId && $userId) { $totalSeconds = 0; $coordinate = []; foreach ($positionsArr as $position) { - /** @var uPosition $prevPosition */ $distance = isset($prevPosition) ? $position->distanceTo($prevPosition) : 0; $seconds = isset($prevPosition) ? $position->secondsTo($prevPosition) : 0; $prevPosition = $position;