Completed
Push — master ( 2ec9f0...d428ee )
by Andrii
30:10 queued 22:08
created

Project::isAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\librariesio;
12
13
use hiqdev\assetpackagist\models\AssetPackage;
14
use hiqdev\assetpackagist\repositories\PackageRepository;
15
use Yii;
16
use yii\base\Model;
17
18
/**
19
 * @property string $fullName Full name of package
20
 */
21
class Project extends Model
22
{
23
    public $name;
24
    public $platform;
25
    public $description;
26
    public $homepage;
27
    public $repository_url;
28
    public $normalized_licenses;
29
    public $rank;
30
    public $latest_release_published_at;
31
    public $latest_release_number;
32
    public $language;
33
    public $status;
34
    public $package_manager_url;
35
    public $stars;
36
    public $forks;
37
    public $keywords;
38
39
    public function rules()
40
    {
41
        return [
42
            ['name', 'string'],
43
            ['platform', 'string'],
44
            ['description', 'string'],
45
            ['homepage', 'url'],
46
            ['repository_url', 'url'],
47
            ['normalized_licenses', 'each', 'rule' => ['string']],
48
            ['rank', 'integer'],
49
            ['latest_release_published_at', 'datetime', 'timestampAttribute' => 'latest_release_published_at'],
50
            ['latest_release_number', 'string'],
51
            ['language', 'string'],
52
            ['status', 'string'],
53
            ['package_manager_url', 'url'],
54
            ['stars', 'integer'],
55
            ['forks', 'integer'],
56
            ['keywords', 'each', 'rule' => ['string']],
57
        ];
58
    }
59
60
    public function getFullName()
61
    {
62
        $fullname = AssetPackage::buildFullName($this->platform, $this->name);
63
        return AssetPackage::normalizeName($fullname);
64
    }
65
66
    /**
67
     * Check the package exists in Asset-Packagist.
68
     * @return boolean
69
     */
70
    public function isAvailable()
71
    {
72
        $package = AssetPackage::fromFullName($this->getFullName());
73
74
        $repository = Yii::createObject(PackageRepository::class, []);
75
76
        return $repository->exists($package);
77
    }
78
}
79