FractalService::item()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
namespace Nord\Lumen\Fractal\Contracts;
4
5
use League\Fractal\Serializer\SerializerAbstract;
6
use League\Fractal\TransformerAbstract;
7
use Nord\Lumen\Fractal\FractalBuilder;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Nord\Lumen\Fractal\Contracts\FractalBuilder.

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...
8
9
interface FractalService
10
{
11
12
    /**
13
     * Serializes a single item.
14
     *
15
     * @param mixed                             $data
16
     * @param TransformerAbstract|callable|null $transformer
17
     * @param string|null                       $resourceKey
18
     *
19
     * @return FractalBuilder
20
     */
21
    public function item($data, TransformerAbstract $transformer = null, $resourceKey = null);
22
23
24
    /**
25
     * Serializes a collection of items.
26
     *
27
     * @param mixed                             $data
28
     * @param TransformerAbstract|callable|null $transformer
29
     * @param string|null                       $resourceKey
30
     *
31
     * @return FractalBuilder
32
     */
33
    public function collection($data, TransformerAbstract $transformer = null, $resourceKey = null);
34
35
36
    /**
37
     * Parses includes from either a string (GET query parameter) or an array
38
     * and stores them so that they are available at the time of serialization.
39
     *
40
     * @param string|array $includes
41
     *
42
     * @see http://fractal.thephpleague.com/transformers#including-data
43
     */
44
    public function parseIncludes($includes);
45
46
47
    /**
48
     * Sets the default serializer to use for serializing data.
49
     *
50
     * @param SerializerAbstract $serializer
51
     *
52
     * @see http://fractal.thephpleague.com/serializers/
53
     */
54
    public function setDefaultSerializer(SerializerAbstract $serializer);
55
}
56