FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Coordinate.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2020 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
12 
18 {
23  private $revision;
24 
29  private $type;
30 
35  private $name;
36 
41  private $provider;
42 
47  private $namespace;
48 
53  private $score;
54 
61  public function __construct($obj)
62  {
63  if (count(array_diff(['type', 'provider', 'name'], array_keys($obj))) == 0) {
64  $this->type = $obj['type'];
65  $this->provider = $obj['provider'];
66  $this->name = $obj['name'];
67  } else {
68  throw new \InvalidArgumentException('type, provider and name are required');
69  }
70  if (array_key_exists('namespace', $obj) && !empty($obj['namespace'])) {
71  $this->namespace = $obj['namespace'];
72  } else {
73  $this->namespace = '-';
74  }
75  if (array_key_exists('revision', $obj) && !empty($obj['revision'])) {
76  $this->revision = $obj['revision'];
77  } else {
78  $this->revision = '';
79  }
80  }
81 
86  public function generateUrlString()
87  {
88  return "$this->type/$this->provider/$this->namespace/$this->name/" .
90  }
91 
95  public function getRevision()
96  {
97  return $this->revision;
98  }
99 
103  public function getType()
104  {
105  return $this->type;
106  }
107 
111  public function getName()
112  {
113  return $this->name;
114  }
115 
119  public function getProvider()
120  {
121  return $this->provider;
122  }
123 
127  public function getNamespace()
128  {
129  return $this->namespace;
130  }
131 
135  public function getScore()
136  {
137  return $this->score;
138  }
139 
147  public static function generateFromString($coordinate)
148  {
149  $parts = explode("/", $coordinate);
150  if (count($parts) != 5) {
151  throw new \InvalidArgumentException("Invalid coordinate string");
152  }
153  $obj = [
154  'type' => $parts[0],
155  'provider' => $parts[1],
156  'namespace' => $parts[2],
157  'name' => $parts[3],
158  'revision' => $parts[4]
159  ];
160  return new Coordinate($obj);
161  }
162 
168  public function setScore($score)
169  {
170  $this->score = intval($score);
171  }
172 }
static generateFromString($coordinate)
Definition: Coordinate.php:147