BasicForm.php
Current file: /home/magister/git/yii-example/example/protected/models/BasicForm.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00% 1 / 1
100.00% 2 / 2 CRAP
100.00% 42 / 42
BasicForm
100.00% 1 / 1
100.00% 2 / 2 2
100.00% 42 / 42
 rules()
100.00% 1 / 1 1
100.00% 35 / 35
 attributeLabels ()
100.00% 1 / 1 1
100.00% 7 / 7


       1                 : <?php                                                                                  
       2                 :                                                                                        
       3                 : /**                                                                                    
       4                 :  * Basic form example.                                                                 
       5                 :  *                                                                                     
       6                 :  * This example is based on the CFormModel which can do basic input                    
       7                 :  * validation and any other processing on that data as necessary. It will              
       8                 :  * demonstrate the validation using various scenarios and produce some                 
       9                 :  * simple output.                                                                      
      10                 :  *                                                                                     
      11                 :  * Note about scenarios: The CFormModel by default the scenario is empty. In           
      12                 :  * the rule if the scenario is not specified then it applies to all                    
      13                 :  * scenarios. In this example the default (empty) scenario is not used.                
      14                 :  */                                                                                    
      15                 : class BasicForm extends CFormModel {                                                   
      16                 :     public $attribute_boolean;                                                         
      17                 :     public $attribute_number;                                                          
      18                 :     public $attribute_range;                                                           
      19                 :     public $attribute_regex;                                                           
      20                 :     public $attribute_string;                                                          
      21                 :     public $attribute_safe;                                                            
      22                 :                                                                                        
      23                 :     public function rules() {                                                          
      24                 :         return array (                                                                 
      25                 :             // scenario_default                                                        
      26                 :             // The following attributes are included in this scenario:                 
      27                 :             //   attribute_boolean                                                     
      28                 :             //   attribute_number                                                      
      29                 :             //   attribute_range                                                       
      30                 :             //   attribute_regex                                                       
      31                 :             //   attribute_string                                                      
      32                 :             //   attribute_safe                                                        
      33                 :             // CRequiredValidator                                                      
      34                 :             array (                                                                    
      35               3 :                 'attribute_number, attribute_range, attribute_regex, attribute_string',
      36               3 :                 'required',                                                            
      37               3 :                 'on' => 'scenario_default',                                            
      38               3 :             ),                                                                         
      39                 :             // CBooleanValidator                                                       
      40                 :             array (                                                                    
      41               3 :                 'attribute_boolean',                                                   
      42               3 :                 'boolean',                                                             
      43               3 :                 'on' => 'scenario_default',                                            
      44               3 :             ),                                                                         
      45                 :             // CNumberValidator                                                        
      46                 :             array (                                                                    
      47               3 :                 'attribute_number',                                                    
      48               3 :                 'numerical',                                                           
      49               3 :                 'min' => 1,                                                            
      50               3 :                 'max' => 10,                                                           
      51               3 :                 'on' => 'scenario_default',                                            
      52               3 :             ),                                                                         
      53                 :             // CRangeValidator                                                         
      54                 :             array (                                                                    
      55               3 :                 'attribute_range',                                                     
      56               3 :                 'in',                                                                  
      57               3 :                 'range' => array (1,3,5,7,9),                                          
      58               3 :                 'on' => 'scenario_default',                                            
      59               3 :             ),                                                                         
      60                 :             // CRegularExpressionValidator                                             
      61                 :             array (                                                                    
      62               3 :                 'attribute_regex',                                                     
      63               3 :                 'match',                                                               
      64               3 :                 'pattern' => '/\w+ \d+/',                                              
      65               3 :                 'message' => '{attribute} must contain a word, a space then a number.',
      66               3 :                 'on' => 'scenario_default',                                            
      67               3 :             ),                                                                         
      68                 :             // CStringValidator                                                        
      69                 :             array (                                                                    
      70               3 :                 'attribute_string',                                                    
      71               3 :                 'length',                                                              
      72               3 :                 'max' => 15,                                                           
      73               3 :                 'on' => 'scenario_default',                                            
      74               3 :             ),                                                                         
      75                 :             array (                                                                    
      76               3 :                 'attribute_safe',                                                      
      77               3 :                 'safe',                                                                
      78               3 :                 'on' => 'scenario_default',                                            
      79               3 :             ),                                                                         
      80               3 :         );                                                                             
      81                 :     }                                                                                  
      82                 :                                                                                        
      83                 :     public function attributeLabels () {                                               
      84                 :         return array (                                                                 
      85               2 :             'attribute_boolean' => 'Boolean (True or False)',                          
      86               2 :             'attribute_number' => 'Number (1 to 10)',                                  
      87               2 :             'attribute_range' => 'Range (1,3,5,7,9)',                                  
      88               2 :             'attribute_regex' => 'Regular expression (word space number)',             
      89               2 :             'attribute_string' => 'String (only 15 characters)',                       
      90               2 :             'attribute_safe' => 'Safe (anything can go here or nothing can)',          
      91               2 :         );                                                                             
      92                 :     }                                                                                  
      93                 :                                                                                        
      94                 : }                                                                                      

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.4.4-14+deb7u2 and PHPUnit 3.6.10 at Wed Aug 14 8:46:00 CDT 2013.