Completed
Push — master ( 9a341d...f10304 )
by Thierry
01:44
created

Validator::validateMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Validator.php - Jaxon input data validator
5
 *
6
 * Validate requests data before the are passed into the library.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Utils\Validation;
16
17
/*
18
 * See the following links to get explanations about the regexp.
19
 * http://php.net/manual/en/language.oop5.basic.php
20
 * http://stackoverflow.com/questions/3195614/validate-class-method-names-with-regex
21
 * http://www.w3schools.com/charsets/ref_html_utf8.asp
22
 * http://www.w3schools.com/charsets/ref_utf_latin1_supplement.asp
23
 */
24
class Validator
25
{
26
    /**
27
     * Validate a function name
28
     *
29
     * @param string        $sName            The function name
30
     *
31
     * @return bool            True if the function name is valid, and false if not
32
     */
33
    public function validateFunction($sName)
34
    {
35
        return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName);
36
    }
37
38
    /**
39
     * Validate an event name
40
     *
41
     * @param string        $sName            The event name
42
     *
43
     * @return bool            True if the event name is valid, and false if not
44
     */
45
    public function validateEvent($sName)
46
    {
47
        return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName);
48
    }
49
50
    /**
51
     * Validate a class name
52
     *
53
     * @param string        $sName            The class name
54
     *
55
     * @return bool            True if the class name is valid, and false if not
56
     */
57
    public function validateClass($sName)
58
    {
59
        return preg_match('/^([a-zA-Z][a-zA-Z0-9_]*)(\.[a-zA-Z][a-zA-Z0-9_]*)*$/', $sName);
60
    }
61
62
    /**
63
     * Validate a method name
64
     *
65
     * @param string        $sName            The function name
66
     *
67
     * @return bool            True if the method name is valid, and false if not
68
     */
69
    public function validateMethod($sName)
70
    {
71
        // return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName);
72
        return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sName);
73
    }
74
75
    /**
76
     * Validate an uploaded file
77
     *
78
     * @param array         $aUploadedFile    The file data received in the $_FILES array
79
     *
80
     * @return bool            True if the file data are valid, and false if not
81
     */
82
    public function validateUploadedFile(array $aUploadedFile)
0 ignored issues
show
Unused Code introduced by
The parameter $aUploadedFile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
    {
84
        return true;
85
    }
86
}
87