Completed
Push — feature/travis-php72-1 ( 57a91d )
by Alexandre
12:03 queued 03:53
created

pluggable-functions.php ➔ is_id()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2014 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
if (!function_exists('url')) {
9
    /**
10
     * Construct a url on the current site.
11
     *
12
     * @param string $path The path of the url.
13
     * @param mixed $domain Whether or not to include the domain. This can be one of the following.
14
     * - false: The domain will not be included.
15
     * - true: The domain will be included.
16
     * - //: A schemeless domain will be included.
17
     * - /: Just the path will be returned.
18
     * @return string Returns the url.
19
     */
20
    function url($path, $domain = false) {
21
        if (is_url($path)) {
22
            return $path;
23
        }
24
25
        return Garden\Request::current()->makeUrl($path, $domain);
26
    }
27
}
28
29
if (!function_exists('is_id')) {
30
    /**
31
     * Finds whether the type given variable is a database id.
32
     *
33
     * @param mixed $val The variable being evaluated.
34
     * @param bool $allow_slugs Whether or not slugs are allowed in the url.
35
     * @return bool Returns `true` if the variable is a database id or `false` if it isn't.
36
     */
37
    function is_id($val, $allow_slugs = false) {
38
        if (is_numeric($val)) {
39
            return true;
40
        } elseif ($allow_slugs && preg_match(`^\d+-`, $val)) {
41
            return true;
42
        } else {
43
            return false;
44
        }
45
    }
46
}