Completed
Push — master ( c64181...1843e0 )
by Adam
13:40
created

StringMixin::fromYaml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format;
4
5
use BestServedCold\PhalueObjects\VOArray\Mixin;
6
7
/**
8
 * Class SringMixin
9
 *
10
 * @package BestServedCold\PhalueObjects\Format
11
 */
12
trait StringMixin
13
{
14
    use Mixin;
15
16
    /**
17
     * @param  Yaml $yaml
18
     * @return Json
19
     */
20
    public static function fromYaml(Yaml $yaml)
21
    {
22
        return static::fromArray($yaml->toArray());
0 ignored issues
show
Bug introduced by
The method fromArray() does not exist on BestServedCold\PhalueObjects\Format\StringMixin. Did you maybe mean fromVOArray()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
23
    }
24
25
    /**
26
     * @return Yaml
27
     */
28
    public function toYaml()
29
    {
30
        return Yaml::fromArray($this->toArray());
0 ignored issues
show
Bug introduced by
It seems like toArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
    }
32
33
    /**
34
     * @param  Xml  $xml
35
     * @return Json
36
     */
37
    public function fromXml(Xml $xml)
38
    {
39
        return static::fromArray($xml->toArray());
0 ignored issues
show
Bug introduced by
The method fromArray() does not exist on BestServedCold\PhalueObjects\Format\StringMixin. Did you maybe mean fromVOArray()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
    }
41
42
    /**
43
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be Xml?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
44
     */
45
    public function toXml()
46
    {
47
        return Xml::fromArray($this->toArray());
0 ignored issues
show
Bug introduced by
It seems like toArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
    }
49
}
50