From 77b87f65a1baea5d31088c531c136231862cc0f3 Mon Sep 17 00:00:00 2001 From: Marco Schlicht <schlicht@itc.rwth-aachen.de> Date: Mon, 19 Mar 2018 13:22:39 +0100 Subject: [PATCH] minor changes --- src/RwthMoodleApiLib/Config.php | 3 +-- src/RwthMoodleApiLib/Controller/CourseRoom.php | 2 +- src/RwthMoodleApiLib/Controller/WhatsNew.php | 2 +- .../Exceptions/BadResponseException.php | 8 ++++---- src/RwthMoodleApiLib/Exceptions/ClientException.php | 8 ++++---- src/RwthMoodleApiLib/Exceptions/HttpException.php | 8 ++++---- src/RwthMoodleApiLib/Exceptions/MoodleException.php | 5 +++++ .../Exceptions/RequestException.php | 8 ++++---- src/RwthMoodleApiLib/Exceptions/ServerException.php | 8 ++++---- src/RwthMoodleApiLib/Injector/Injector.php | 8 +++++--- src/RwthMoodleApiLib/RwthMoodleApiLib.php | 13 +++++++------ .../Controller/AnnouncementTest.php | 8 ++++---- tests/RwthMoodleApiLib/Controller/WhatsNewTest.php | 2 +- 13 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/RwthMoodleApiLib/Config.php b/src/RwthMoodleApiLib/Config.php index 27b12a1..97d8d46 100644 --- a/src/RwthMoodleApiLib/Config.php +++ b/src/RwthMoodleApiLib/Config.php @@ -40,10 +40,9 @@ namespace RwthMoodleApiLib; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @link https://git.rwth-aachen.de/moodle/rwth_moodle_api **/ -namespace RwthMoodleApiLib; - class Config { + public static $debug_msgs = false; public static $moodle_url = "https://d-mo01.devlef.campus.rwth-aachen.de/moodlems/"; } ?> diff --git a/src/RwthMoodleApiLib/Controller/CourseRoom.php b/src/RwthMoodleApiLib/Controller/CourseRoom.php index 6381cfd..2fa8237 100644 --- a/src/RwthMoodleApiLib/Controller/CourseRoom.php +++ b/src/RwthMoodleApiLib/Controller/CourseRoom.php @@ -79,7 +79,7 @@ class CourseRoom extends ApiController implements CourseRoomInterface $dataSet = array(); foreach ($courses as $course) { //TODO - $closed = !(((int)$course->enddate)===0 || ((int)$course->enddate)>time()); + /* $closed = !(((int)$course->enddate)===0 || ((int)$course->enddate)>time()); */ $uniqueid = $course->id; // "12ws-00000", $semester = "TODO"; // "ws12", diff --git a/src/RwthMoodleApiLib/Controller/WhatsNew.php b/src/RwthMoodleApiLib/Controller/WhatsNew.php index 4a89007..e457020 100644 --- a/src/RwthMoodleApiLib/Controller/WhatsNew.php +++ b/src/RwthMoodleApiLib/Controller/WhatsNew.php @@ -93,7 +93,7 @@ class WhatsNew extends CourseRoom implements WhatsNewInterface $sharedDocuments = array(); $wikis = array(); foreach ($updates->instances as $update) { - print_r($update); + /* print_r($update); */ /* $params_mod = array("cmid"=>$update->id); */ /* print_r($params_mod); */ /* $module_raw = $this->getApi()->restCall('core_course_get_course_module', $params_mod); */ diff --git a/src/RwthMoodleApiLib/Exceptions/BadResponseException.php b/src/RwthMoodleApiLib/Exceptions/BadResponseException.php index 6064e31..5eadb86 100644 --- a/src/RwthMoodleApiLib/Exceptions/BadResponseException.php +++ b/src/RwthMoodleApiLib/Exceptions/BadResponseException.php @@ -50,12 +50,12 @@ class BadResponseException extends RequestException implements BadResponseExcept /** * Constructor * - * @param \GuzzleHttp\Exception\BadResponseException $gz Exception to wrap + * @param \GuzzleHttp\Exception\BadResponseException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\BadResponseException $gz) + public function __construct(\GuzzleHttp\Exception\BadResponseException $gzhttp) { - parent::__construct($gz); - $this->badResponseException = $gz; + parent::__construct($gzhttp); + $this->badResponseException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/ClientException.php b/src/RwthMoodleApiLib/Exceptions/ClientException.php index cbc1494..c49c4ef 100644 --- a/src/RwthMoodleApiLib/Exceptions/ClientException.php +++ b/src/RwthMoodleApiLib/Exceptions/ClientException.php @@ -50,12 +50,12 @@ class ClientException extends BadResponseException implements ClientExceptionInt /** * Constructor * - * @param \GuzzleHttp\Exception\ClientException $gz Exception to wrap + * @param \GuzzleHttp\Exception\ClientException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\ClientException $gz) + public function __construct(\GuzzleHttp\Exception\ClientException $gzhttp) { - parent::__construct($gz); - $this->clientException = $gz; + parent::__construct($gzhttp); + $this->clientException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/HttpException.php b/src/RwthMoodleApiLib/Exceptions/HttpException.php index 0ce0f87..2454077 100644 --- a/src/RwthMoodleApiLib/Exceptions/HttpException.php +++ b/src/RwthMoodleApiLib/Exceptions/HttpException.php @@ -50,12 +50,12 @@ class HttpException extends RwthMoodleApiLibException implements HttpExceptionIn /** * Constructor * - * @param \GuzzleHttp\Exception\TransferException $gz exception to wrap + * @param \GuzzleHttp\Exception\TransferException $gzhttp exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\TransferException $gz) + public function __construct(\GuzzleHttp\Exception\TransferException $gzhttp) { - parent::__construct($gz); - $this->httpException = $gz; + parent::__construct($gzhttp); + $this->httpException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/MoodleException.php b/src/RwthMoodleApiLib/Exceptions/MoodleException.php index e0f6fc4..31e4a3e 100644 --- a/src/RwthMoodleApiLib/Exceptions/MoodleException.php +++ b/src/RwthMoodleApiLib/Exceptions/MoodleException.php @@ -105,6 +105,11 @@ class MoodleException extends MoodleResponseException implements MoodleException return $this->moodleMessage; } + /** + * Returns the error message as a string + * + * @return string error message + **/ public function __toString() : string { diff --git a/src/RwthMoodleApiLib/Exceptions/RequestException.php b/src/RwthMoodleApiLib/Exceptions/RequestException.php index 7603b3e..a8c5063 100644 --- a/src/RwthMoodleApiLib/Exceptions/RequestException.php +++ b/src/RwthMoodleApiLib/Exceptions/RequestException.php @@ -53,12 +53,12 @@ class RequestException extends HttpException implements RequestExceptionInterfac /** * Constructor * - * @param \GuzzleHttp\Exception\RequestInterface $gz RequestException to wrap + * @param \GuzzleHttp\Exception\RequestInterface $gzhttp RequestException to wrap **/ - public function __construct(\GuzzleHttp\Exception\RequestException $gz) + public function __construct(\GuzzleHttp\Exception\RequestException $gzhttp) { - parent::__construct($gz); - $this->requestException = $gz; + parent::__construct($gzhttp); + $this->requestException = $gzhttp; } /** diff --git a/src/RwthMoodleApiLib/Exceptions/ServerException.php b/src/RwthMoodleApiLib/Exceptions/ServerException.php index 4065b79..c56474f 100644 --- a/src/RwthMoodleApiLib/Exceptions/ServerException.php +++ b/src/RwthMoodleApiLib/Exceptions/ServerException.php @@ -50,12 +50,12 @@ class ServerException extends BadResponseException implements BadResponseExcepti /** * Constructor * - * @param \GuzzleHttp\Exception\ServerException $gz Exception to wrap + * @param \GuzzleHttp\Exception\ServerException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\ServerException $gz) + public function __construct(\GuzzleHttp\Exception\ServerException $gzhttp) { - parent::__construct($gz); - $this->serverException = $gz; + parent::__construct($gzhttp); + $this->serverException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Injector/Injector.php b/src/RwthMoodleApiLib/Injector/Injector.php index 0eb8654..974b440 100644 --- a/src/RwthMoodleApiLib/Injector/Injector.php +++ b/src/RwthMoodleApiLib/Injector/Injector.php @@ -55,15 +55,17 @@ class Injector implements InjectorInterface /** * Constructor + * + * @param string $url The url to moodle **/ - public function __construct($url=Null) + public function __construct($url=null) { //observers - $informationalObserver = new Logging\ConsoleLogger(6); + $infoObserver = new Logging\ConsoleLogger(6); $warningObserver = new Logging\ConsoleLogger(4); $criticalObserver = new Logging\ConsoleLogger(2); $this->observers = array( - "informational" => $informationalObserver, + "informational" => $infoObserver, "warning" => $warningObserver, "critical" => $criticalObserver ); diff --git a/src/RwthMoodleApiLib/RwthMoodleApiLib.php b/src/RwthMoodleApiLib/RwthMoodleApiLib.php index 42daedb..3a326b1 100644 --- a/src/RwthMoodleApiLib/RwthMoodleApiLib.php +++ b/src/RwthMoodleApiLib/RwthMoodleApiLib.php @@ -99,10 +99,9 @@ class RwthMoodleApiLib implements RwthMoodleApiLibInterface throw new Exceptions\MoodleError($login->error, $login->errorcode, $response); } else if (empty($login->token) && empty($login->privatetoken)) { return false; - } else { - $this->moodleToken = $login->token??$login->privatetoken; - return true; } + $this->moodleToken = $login->token??$login->privatetoken; + return true; } /** @@ -128,13 +127,15 @@ class RwthMoodleApiLib implements RwthMoodleApiLibInterface } else if (!empty($login->exception)) { throw new Exceptions\MoodleException($login->exception, $login->errorcode, $login->message, $response); } else if (!empty($login->error)) { + if (Config::$debug_msgs) { + print_r($login); + } throw new Exceptions\MoodleError($login->error, $login->errorcode, $response); } else if (empty($login->token) && empty($login->privatetoken)) { return false; - } else { - $this->moodleToken = $login->token??$login->privatetoken; - return true; } + $this->moodleToken = $login->token??$login->privatetoken; + return true; } /** diff --git a/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php b/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php index fe3d0f5..a2330ba 100644 --- a/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php +++ b/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php @@ -70,15 +70,15 @@ final class AnnouncementTest extends TestCase } /** - * Test case for viewAllCourseInfo + * Test case for viewAllAnnouncements * - * @covers RwthMoodleApiLib\Controller\Announcement::viewAllCourseInfo() + * @covers RwthMoodleApiLib\Controller\Announcement::viewAllAnnouncements() * * @return none **/ - public function testViewAllCourseInfo() + public function testViewAllAnnouncements() { - $announcement = $this->announcement->viewAllAnnouncements(3); + $announcement = $this->announcement->viewAllAnnouncements(2); $this->assertTrue(true); } diff --git a/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php b/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php index 2b937a3..0e0ba1a 100644 --- a/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php +++ b/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php @@ -78,7 +78,7 @@ final class WhatsNewTest extends TestCase **/ public function testWhatsNewSince() { - $this->whatsNew->whatsNewSince(3, 99999); + $this->whatsNew->whatsNewSince(2, 99999); $this->assertTrue(true); } -- GitLab