Completed
Pull Request — master (#5)
by Dan Michael O.
01:38
created

Bookshelf::getUid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Scriptotek\GoogleBooks;
4
5
class Bookshelf extends Model
6
{
7
    /**
8
     * Get the user id for this bookshelf.
9
     *
10
     * @return string
11
     */
12
    public function getUid()
13
    {
14
        $selfLinkParts = explode('/', $this->selfLink);
0 ignored issues
show
Documentation introduced by
The property selfLink does not exist on object<Scriptotek\GoogleBooks\Bookshelf>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
15
        return $selfLinkParts[count($selfLinkParts) - 3];
16
    }
17
18
    /**
19
     * Get the volumes contained in this bookshelf.
20
     *
21
     * @return Volume[]
22
     */
23
    public function getVolumes()
24
    {
25
        $endpoint = sprintf('users/%s/bookshelves/%s/volumes', $this->getUid(), $this->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Scriptotek\GoogleBooks\Bookshelf>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
        $volumes = [];
27
        foreach ($this->client->listItems($endpoint) as $item) {
28
            $volumes[] = new Volume($this->client, $item);
29
        }
30
        return $volumes;
31
    }
32
}
33