Test Failed
Pull Request — master (#171)
by Zaahid
04:55
created

DefaultProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 22 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace ZBateson\MailMimeParser;
8
9
use ZBateson\MailMimeParser\Message\PartHeaderContainer;
10
use ZBateson\MailMimeParser\Message\PartChildrenContainer;
11
use Pimple\Container;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ZBateson\MailMimeParser\Container. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use Pimple\ServiceProviderInterface;
13
14
/**
15
 * Default Pimple\ServiceProviderInterface defining classes that require
16
 * factories or special configuration on initialization.
17
 *
18
 * @author Zaahid Bateson
19
 */
20
class DefaultProvider implements ServiceProviderInterface
21
{
22
    public function register(Container $pimple)
23
    {
24
        $pimple['\ZBateson\MailMimeParser\Message\PartStreamContainer'] = $pimple->factory(function() use ($pimple) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
25
            $factory = $pimple['\ZBateson\MailMimeParser\Message\Factory\PartStreamContainerFactory'];
26
            return $factory->newInstance();
27
        });
28
        $pimple['\ZBateson\MailMimeParser\Message\PartHeaderContainer'] = $pimple->factory(function() use ($pimple) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
29
            return new PartHeaderContainer($pimple['\ZBateson\MailMimeParser\Header\HeaderFactory']);
30
        });
31
        $pimple['\ZBateson\MailMimeParser\Message\PartChildrenContainer'] = $pimple->factory(function() use ($pimple) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The import $pimple is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
32
            return new PartChildrenContainer();
33
        });
34
35
        // This might need to move somewhere else. 'extend' doesn't work because BaseParser
36
        // is a dependency of the other parsers, and using extend causes it to be called
37
        // recursively when trying to create an instance of a parser and BaseParser
38
        // is not yet registered on Pimple\Container
39
        $baseParser = $pimple['\ZBateson\MailMimeParser\Parser\BaseParser'];
40
        $baseParser->addContentParser($pimple['\ZBateson\MailMimeParser\Parser\MimeContentParser']);
41
        $baseParser->addContentParser($pimple['\ZBateson\MailMimeParser\Parser\NonMimeParser']);
42
        $baseParser->addChildParser($pimple['\ZBateson\MailMimeParser\Parser\MultipartChildrenParser']);
43
        $baseParser->addChildParser($pimple['\ZBateson\MailMimeParser\Parser\NonMimeParser']);
44
    }
45
}
46