| 1 | <?php namespace Arcanesoft\Auth\Rules; |
||
| 13 | class OldPasswordRule implements Rule |
||
| 14 | { |
||
| 15 | /* ----------------------------------------------------------------- |
||
| 16 | | Properties |
||
| 17 | | ----------------------------------------------------------------- |
||
| 18 | */ |
||
| 19 | |||
| 20 | /** @var \Illuminate\Contracts\Auth\Authenticatable */ |
||
| 21 | protected $user; |
||
| 22 | |||
| 23 | /* ----------------------------------------------------------------- |
||
| 24 | | Constructor |
||
| 25 | | ----------------------------------------------------------------- |
||
| 26 | */ |
||
| 27 | |||
| 28 | /** |
||
| 29 | * OldPasswordRule constructor. |
||
| 30 | * |
||
| 31 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
| 32 | */ |
||
| 33 | public function __construct(Authenticatable $user) |
||
| 37 | |||
| 38 | /* ----------------------------------------------------------------- |
||
| 39 | | Main Methods |
||
| 40 | | ----------------------------------------------------------------- |
||
| 41 | */ |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Determine if the validation rule passes. |
||
| 45 | * |
||
| 46 | * @param string $attribute |
||
| 47 | * @param mixed $value |
||
| 48 | * |
||
| 49 | * @return bool |
||
| 50 | */ |
||
| 51 | public function passes($attribute, $value) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get the validation error message. |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function message() |
||
| 65 | } |
||
| 66 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.