Completed
Push — master ( c0ede7...0a2d54 )
by
unknown
02:00 queued 10s
created

Game::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 12
cts 12
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Syntax\SteamApi\Containers;
4
5
class Game 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 3
    public function __construct($app)
28
    {
29 3
        $this->appId                    = $app->appid;
30 3
        $this->name                     = $this->checkIssetField($app, 'name');
31 3
        $this->playtimeTwoWeeks         = $this->checkIssetField($app, 'playtime_2weeks', 0);
32 3
        $this->playtimeTwoWeeksReadable = $this->convertFromMinutes($this->playtimeTwoWeeks);
33 3
        $this->playtimeForever          = $this->checkIssetField($app, 'playtime_forever', 0);
34 3
        $this->playtimeForeverReadable  = $this->convertFromMinutes($this->playtimeForever);
35 3
        $this->icon                     = $this->checkIssetImage($app, 'img_icon_url');
36 3
        $this->logo                     = $this->checkIssetImage($app, 'img_logo_url');
37 3
        $this->header                   = 'http://cdn.akamai.steamstatic.com/steam/apps/' . $this->appId . '/header.jpg';
38 3
        $this->hasCommunityVisibleStats = $this->checkIssetField($app, 'has_community_visible_stats', 0);
39 3
    }
40
41
    /**
42
     * @param        $app
43
     * @param string $field
44
     * @param string $value
45
     *
46
     * @return null|string
47
     */
48 3
    protected function checkIssetImage($app, $field, $value = null)
49
    {
50 3
        return isset($app->$field) ? $this->getImageForGame($app->appid, $app->$field) : $value;
51
    }
52
53 2
    protected function getImageForGame($appId, $hash)
54
    {
55 2
        if ($hash != null) {
56 2
            return 'http://media.steampowered.com/steamcommunity/public/images/apps/' . $appId . '/' . $hash . '.jpg';
57
        }
58
59
        return null;
60
    }
61
}
62