| Conditions | 5 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | public function __construct($metric_class, $var, $help, $labels) |
||
| 8 | { |
||
| 9 | if (!preg_match('/^[a-zA-Z_:][a-zA-Z0-9_:]*$/', $var)) { |
||
| 10 | throw new Exceptions\InvalidName(sprintf( |
||
| 11 | "Metric name '%s' is invalid", |
||
| 12 | $var |
||
| 13 | )); |
||
| 14 | } |
||
| 15 | foreach ($labels as $label) { |
||
| 16 | if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $label) |
||
| 17 | or substr($label, 0, 4) === "__") { |
||
|
|
|||
| 18 | throw new Exceptions\InvalidName(sprintf( |
||
| 19 | "Label name '%s' is invalid", |
||
| 20 | $label |
||
| 21 | )); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | $this->metric_class = "Aptarus\\PromClient\\" . $metric_class; |
||
| 25 | $this->var = $var; |
||
| 26 | $this->help = $help; |
||
| 27 | $this->labels = $labels; |
||
| 28 | } |
||
| 29 | |||
| 49 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.