Completed
Pull Request — 5.x (#16)
by Lars
05:10
created

Swift   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 35%
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 63
ccs 7
cts 20
cp 0.35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
B autoload() 0 22 6
A registerAutoload() 0 7 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 $inits = array();
23
24
    /**
25
     * Registers an initializer callable that will be called the first time
26
     * a SwiftMailer class is autoloaded.
27
     *
28
     * This enables you to tweak the default configuration in a lazy way.
29
     *
30
     * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
31
     */
32
    public static function init($callable)
33
    {
34
        self::$inits[] = $callable;
35
    }
36
37
    /**
38
     * Internal autoloader for spl_autoload_register().
39
     *
40
     * @param string $class
41
     */
42 62
    public static function autoload($class)
43
    {
44
        // Don't interfere with other autoloaders
45 62
        if (0 !== strpos($class, 'Swift_')) {
46
            return;
47
        }
48
49 62
        $path = __DIR__ . '/' . str_replace('_', '/', $class) . '.php';
50
51 62
        if (!file_exists($path)) {
52
            return;
53
        }
54
55 62
        require $path;
56
57 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...
58
            self::$initialized = true;
59
            foreach (self::$inits as $init) {
60
                call_user_func($init);
61
            }
62
        }
63 62
    }
64
65
    /**
66
     * Configure autoloading using Swift Mailer.
67
     *
68
     * This is designed to play nicely with other autoloaders.
69
     *
70
     * @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
71
     */
72
    public static function registerAutoload($callable = null)
73
    {
74
        if (null !== $callable) {
75
            self::$inits[] = $callable;
76
        }
77
        spl_autoload_register(array('Swift', 'autoload'));
78
    }
79
}
80