Completed
Push — v0.7 ( 7c9b41...5c4e91 )
by Nate
02:30
created

DefaultContext::addAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
declare(strict_types=1);
7
8
namespace Tebru\Gson\Internal;
9
10
use Tebru\Gson\Context;
11
12
abstract class DefaultContext implements Context
13
{
14
    protected $attributes = [];
15
16
    protected $enableScalarAdapters = false;
17
18
    /**
19
     * Get an array of user defined attributes
20
     *
21
     * @return array
22
     */
23
    public function getAttributes(): array
24
    {
25
26
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
27
28
    /**
29
     * Returns the attribute value for a given key or null if it's missing
30
     *
31
     * @param string $key
32
     * @return mixed
33
     */
34
    public function getAttribute(string $key)
35
    {
36
37
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
38
39
    /**
40
     * Add a custom attribute
41
     *
42
     * @param string $key
43
     * @param $value
44
     * @return DefaultContext
45
     */
46
    public function addAttribute(string $key, $value): DefaultContext
47
    {
48
49
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Tebru\Gson\Internal\DefaultContext. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
50
51
    /**
52
     * If scalar values should get sent through the type adapter
53
     * system or if they should just be read/written in place.
54
     *
55
     * @return bool
56
     */
57
    public function enableScalarAdapters(): bool
58
    {
59
        return $this->enableScalarAdapters;
60
    }
61
62
    /**
63
     * Defaults to true. Set to false if scalar values should be read/written
64
     * through a type adapter.
65
     *
66
     * @param bool $enable
67
     * @return mixed
68
     */
69
    public function setEnableScalarAdapters(bool $enable)
70
    {
71
72
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
73
}
74