Passed
Pull Request — master (#6869)
by Michael
09:57
created

ClassMetadataExporter::getExporter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 4
cts 5
cp 0.8
crap 2.032
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Tools\Export;
21
22
/**
23
 * Class used for converting your mapping information between the
24
 * supported formats: yaml, xml, and php/annotation.
25
 *
26
 * @link    www.doctrine-project.org
27
 * @since   2.0
28
 * @author  Jonathan Wage <[email protected]>
29
 *
30
 * @deprecated
31
 */
32
class ClassMetadataExporter
33
{
34
    /**
35
     * @var array
36
     */
37
    private static $_exporterDrivers = [
38
        'xml' => Driver\XmlExporter::class,
39
        'yaml' => Driver\YamlExporter::class,
40
        'yml' => Driver\YamlExporter::class,
41
        'php' => Driver\PhpExporter::class,
42
        'annotation' => Driver\AnnotationExporter::class
43
    ];
44
45 6
    public function __construct()
46
    {
47 6
        @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED);
48 6
    }
49
50
    /**
51
     * Registers a new exporter driver class under a specified name.
52
     *
53
     * @param string $name
54
     * @param string $class
55
     *
56
     * @return void
57
     */
58
    public static function registerExportDriver($name, $class)
59
    {
60
        self::$_exporterDrivers[$name] = $class;
61
    }
62
63
    /**
64
     * Gets an exporter driver instance.
65
     *
66
     * @param string      $type The type to get (yml, xml, etc.).
67
     * @param string|null $dest The directory where the exporter will export to.
68
     *
69
     * @return Driver\AbstractExporter
70
     *
71
     * @throws ExportException
72
     */
73 6
    public function getExporter($type, $dest = null)
74
    {
75 6
        if ( ! isset(self::$_exporterDrivers[$type])) {
76
            throw ExportException::invalidExporterDriverType($type);
77
        }
78
79 6
        $class = self::$_exporterDrivers[$type];
80
81 6
        return new $class($dest);
82
    }
83
}
84