Completed
Pull Request — master (#110)
by Tobias
13:01 queued 04:23
created

functions.php ➔ safe_class_exists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Http\Discovery;
4
5
/**
6
 * We want to do a "safe" version of PHP's "class_exists" because Magento has a bug
7
 * (or they call it a "feature"). Magento is throwing an exception if you do class_exists()
8
 * on a class that ends with "Factory" and if that file does not exits.
9
 *
10
 * This function will catch all potential exceptions and make sure it returns a boolean.
11
 *
12
 * @param string $class
13
 * @param bool   $autoload
14
 *
15
 * @return bool
16
 */
17
function safe_class_exists($class, $autoload = true)
18
{
19
    try {
20
        return class_exists($class, $autoload);
21
    } catch (\Exception $e) {
22
        return false;
23
    }
24
}
25