Completed
Push — master ( 5033a0...1e3f35 )
by Travis
02:10
created

Item::convertFromMinutes()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 8.439
cc 6
eloc 17
nc 18
nop 1
1
<?php
2
3
namespace Syntax\SteamApi\Containers;
4
5
class Item extends BaseContainer
6
{
7
    public $appId;
8
9
    public $name;
10
11
    public $playtimeTwoWeeks;
12
13
    public $playtimeTwoWeeksReadable;
14
15
    public $playtimeForever;
16
17
    public $playtimeForeverReadable;
18
19
    public $icon;
20
21
    public $logo;
22
23
    public $header;
24
25
    public $hasCommunityVisibleStats;
26
27
    public function __construct($app)
28
    {
29
        $this->appId                    = $app->appid;
30
        $this->name                     = $this->checkIssetField($app, 'name');
31
        $this->playtimeTwoWeeks         = $this->checkIssetField($app, 'playtime_2weeks', 0);
32
        $this->playtimeTwoWeeksReadable = $this->convertFromMinutes($this->playtimeTwoWeeks);
33
        $this->playtimeForever          = $this->checkIssetField($app, 'playtime_forever', 0);
34
        $this->playtimeForeverReadable  = $this->convertFromMinutes($this->playtimeForever);
35
        $this->icon                     = $this->checkIssetImage($app, 'img_icon_url');
36
        $this->logo                     = $this->checkIssetImage($app, 'img_logo_url');
37
        $this->header                   = 'http://cdn.steampowered.com/v/gfx/apps/' . $this->appId . '/header.jpg';
38
        $this->hasCommunityVisibleStats = $this->checkIssetField($app, 'has_community_visible_stats', 0);
39
    }
40
41
    /**
42
     * @param        $app
43
     * @param string $field
44
     * @param string $value
45
     *
46
     * @return null|string
47
     */
48
    protected function checkIssetImage($app, $field, $value = null)
49
    {
50
        return isset($app->$field) ? $this->getImageForGame($app->appid, $app->$field) : $value;
51
    }
52
53
    protected function getImageForGame($appId, $hash)
54
    {
55
        if ($hash != null) {
56
            return 'http://media.steampowered.com/steamcommunity/public/images/apps/' . $appId . '/' . $hash . '.jpg';
57
        }
58
59
        return null;
60
    }
61
}
62