-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3fd88f
commit 5136943
Showing
33 changed files
with
215 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,36 +15,49 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Сlass status. | ||
* Сlass fail. | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_catquiz\local; | ||
|
||
use Exception; | ||
use local_catquiz\local\status; | ||
|
||
/** | ||
* Provides methods to obtain results. | ||
* | ||
* Overrides abstract methods from result | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class none extends result { | ||
class fail extends result { | ||
/** | ||
* Just returns the current result | ||
* | ||
* @return result | ||
*/ | ||
public function and_then(callable $op): result { | ||
return $this; | ||
} | ||
|
||
/** | ||
* Calls the given callable | ||
* | ||
* @return result | ||
*/ | ||
public function or_else(callable $op): result { | ||
return $op($this); | ||
} | ||
|
||
public function expect() { | ||
/** | ||
* Throws an exception | ||
* | ||
* @throws Exception | ||
*/ | ||
public function expect(): result { | ||
throw new Exception($this->geterrormessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,10 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Сlass status. | ||
* Сlass result. | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
|
@@ -30,9 +30,8 @@ | |
/** | ||
* Provides methods to obtain results. | ||
* | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
abstract class result { | ||
|
@@ -63,33 +62,43 @@ public function __construct($value = null, string $status = status::OK) { | |
* @param string $status | ||
* @param mixed|null $value | ||
* | ||
* @return none | ||
* | ||
* @return fail | ||
*/ | ||
public static function err(string $status = status::ERROR_GENERAL, $value = null) { | ||
return new none($value, $status); | ||
public static function err(string $status = status::ERROR_GENERAL, $value = null): fail { | ||
return new fail($value, $status); | ||
} | ||
|
||
/** | ||
* Returns OK result. | ||
* | ||
* @param mixed|null $value | ||
* | ||
* @return some | ||
* | ||
* @return success | ||
*/ | ||
public static function ok($value = null) { | ||
return new some($value, status::OK); | ||
public static function ok($value = null): success { | ||
return new success($value, status::OK); | ||
} | ||
|
||
/** | ||
* Calls the given callable if successful | ||
* | ||
* @return result | ||
*/ | ||
abstract public function and_then(callable $op): result; | ||
|
||
/** | ||
* Calls the given callable if not successful | ||
* | ||
* @return result | ||
*/ | ||
abstract public function or_else(callable $op): result; | ||
|
||
/** | ||
* Throws an exception if not successful | ||
* | ||
* @throws Exception | ||
*/ | ||
abstract public function expect(); | ||
abstract public function expect(): result; | ||
|
||
/** | ||
* Returns status. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,36 +15,45 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Сlass status. | ||
* Сlass success. | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_catquiz\local; | ||
|
||
use local_catquiz\local\status; | ||
|
||
/** | ||
* Provides methods to obtain results. | ||
* | ||
* Overrides abstract methods from result | ||
* | ||
* @package local_catquiz | ||
* @copyright 2023 Wunderbyte GmbH <[email protected]> | ||
* @copyright 2025 Wunderbyte GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class some extends result { | ||
|
||
class success extends result { | ||
/** | ||
* Calls the given callable | ||
* | ||
* @return result | ||
*/ | ||
public function and_then(callable $op): result { | ||
return $op($this); | ||
} | ||
|
||
/** | ||
* Just returns the current result | ||
* | ||
* @return result | ||
*/ | ||
public function or_else(callable $op): result { | ||
return $this; | ||
} | ||
|
||
public function expect() { | ||
/** | ||
* Just returns the current result | ||
*/ | ||
public function expect(): result { | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.