Completed
Push — 5.x ( b7e0f5...831ff0 )
by Lars
16:50 queued 10:32
created

Swift   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 44.83%
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 85
ccs 13
cts 29
cp 0.4483
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A strtolowerWithStaticCache() 0 12 2
B autoload() 0 22 6
A registerAutoload() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2004-2009 Chris Corbyn
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * General utility class in Swift Mailer, not to be instantiated.
13
 *
14
 *
15
 * @author Chris Corbyn
16
 */
17
abstract class Swift
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
18
{
19
    const VERSION = '5.x';
20
21
    public static $initialized = false;
22
    public static $useMemorySpool = false;
23
    public static $inits = array();
24
25
    /**
26
     * Registers an initializer callable that will be called the first time
27
     * a SwiftMailer class is autoloaded.
28
     *
29
     * This enables you to tweak the default configuration in a lazy way.
30
     *
31
     * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
32
     */
33
    public static function init($callable)
34
    {
35
        self::$inits[] = $callable;
36
    }
37
38
    /**
39
     * Internal autoloader for spl_autoload_register().
40
     *
41
     * @param string $class
42
     */
43 62
    public static function autoload($class)
44
    {
45
        // "maybe" don't interfere with other autoloaders
46 62
        if (0 !== strpos($class, 'Swift_')) {
47
            return;
48
        }
49
50 62
        $path = __DIR__ . '/' . str_replace('_', '/', $class) . '.php';
51
52 62
        if (!file_exists($path)) {
53
            return;
54
        }
55
56 62
        require $path;
57
58 62
        if (self::$inits && !self::$initialized) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$inits of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
59
            self::$initialized = true;
60
            foreach (self::$inits as $init) {
61
                call_user_func($init);
62
            }
63
        }
64 62
    }
65
66
    /**
67
     * Configure autoloading using Swift Mailer.
68
     *
69
     * This is designed to play nicely with other autoloaders.
70
     *
71
     * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
72
     */
73
    public static function registerAutoload($callable = null)
74
    {
75
        if (null !== $callable) {
76
            self::$inits[] = $callable;
77
        }
78
79
        spl_autoload_register(array('Swift', 'autoload'));
80
    }
81
82
    /**
83
     * php-strtolower with static-cache
84
     *
85
     * @param $string
86
     *
87
     * @return mixed
88
     */
89 316
    public static function strtolowerWithStaticCache($string)
90
    {
91 316
        static $staticStrtolowerCache = array();
92
93 316
        if (isset($staticStrtolowerCache[$string])) {
94 310
            return $staticStrtolowerCache[$string];
95
        } else {
96 30
            $staticStrtolowerCache[$string] = strtolower($string);
97
98 30
            return $staticStrtolowerCache[$string];
99
        }
100
    }
101
}
102