Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Demonstration of Processor))
  4.  */
  5. class SomeClass
  6. {
  7.     /** @type string[] */
  8.     private $allowedParam2Values = ['first', 'second', 'third'];
  9.  
  10.     /**
  11.      * Some first processor
  12.      *
  13.      * @type int           $id
  14.      * @type string        $param2
  15.      * @type SomeInterface $param3
  16.      */
  17.     public function someProcessor1($id, $param2, SomeInterface $param3)
  18.     {
  19.         if (!is_int($id)) {
  20.             throw new \InvalidArgumentException('Param id must be int');
  21.         }
  22.        
  23.         if ($id < 0) {
  24.             throw new \InvalidArgumentException('Param id must be more than 0');
  25.         }
  26.        
  27.         if (!is_string($param2)) {
  28.             throw new \InvalidArgumentException('Param param2 must be int');
  29.         }
  30.        
  31.         if (!in_array($param2, $this->allowedParam2Values)) {
  32.             throw new \InvalidArgumentException('Param param2 out of range');
  33.         }
  34.        
  35.         // Some business logic here
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement