Minor code cleanup

This commit is contained in:
Bartek Fabiszewski 2019-05-23 10:58:57 +02:00
parent eeb7ec7532
commit cd5255cbb8
11 changed files with 26 additions and 22 deletions

View File

@ -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) {

View File

@ -1,5 +1,7 @@
<?php
use Psr\Http\Message\ResponseInterface;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(ROOT_DIR . "/helpers/config.php");
@ -788,7 +790,10 @@ class ImportTest extends UloggerAPITestCase {
$this->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);

View File

@ -1,5 +1,7 @@
<?php
use Psr\Http\Message\ResponseInterface;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(ROOT_DIR . "/helpers/config.php");
@ -964,7 +966,10 @@ class InternalAPITest extends UloggerAPITestCase {
$this->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);

View File

@ -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}");
}
}
}

View File

@ -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"
}
}

View File

@ -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)) {

View File

@ -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 = [];

View File

@ -31,11 +31,6 @@
public $isValid = false;
/**
* @var uDb $db
*/
private static $db = null;
/**
* Constructor
*

View File

@ -34,8 +34,6 @@
public $isAdmin = false;
public $isValid = false;
private static $db = null;
/**
* Constructor
*

View File

@ -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')
);

View File

@ -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;