Subversion Repositories oidplus

Rev

Rev 1121 | Rev 1139 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1121 Rev 1130
Line 22... Line 22...
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusGs1 extends OIDplusObject {
26
class OIDplusGs1 extends OIDplusObject {
-
 
27
        /**
-
 
28
         * @var int|string
-
 
29
         */
27
        private $number;
30
        private $number;
28
 
31
 
29
        /**
32
        /**
30
         * @param $number
33
         * @param string|int $number
31
         */
34
         */
32
        public function __construct($number) {
35
        public function __construct($number) {
33
                // TODO: syntax checks
36
                // TODO: syntax checks
34
                $this->number = $number;
37
                $this->number = $number;
35
        }
38
        }
Line 102... Line 105...
102
        }
105
        }
103
 
106
 
104
        /**
107
        /**
105
         * @param OIDplusObject $parent
108
         * @param OIDplusObject $parent
106
         * @return string
109
         * @return string
-
 
110
         * @throws OIDplusException
107
         */
111
         */
108
        public function crudShowId(OIDplusObject $parent): string {
112
        public function crudShowId(OIDplusObject $parent): string {
109
                return $this->chunkedNotation(false);
113
                return $this->chunkedNotation(false);
110
        }
114
        }
111
 
115
 
112
        /**
116
        /**
113
         * @return string
117
         * @return string
-
 
118
         * @throws OIDplusException
114
         */
119
         */
115
        public function crudInsertPrefix(): string {
120
        public function crudInsertPrefix(): string {
116
                return $this->isRoot() ? '' : $this->chunkedNotation(false);
121
                return $this->isRoot() ? '' : $this->chunkedNotation(false);
117
        }
122
        }
118
 
123
 
Line 253... Line 258...
253
         */
258
         */
254
        public function checkDigit(): int {
259
        public function checkDigit(): int {
255
                $mul = 3;
260
                $mul = 3;
256
                $sum = 0;
261
                $sum = 0;
257
                for ($i=strlen($this->number)-1; $i>=0; $i--) {
262
                for ($i=strlen($this->number)-1; $i>=0; $i--) {
-
 
263
                        $str = "".$this->number;
258
                        $sum += $this->number[$i] * $mul;
264
                        $sum += (int)$str[$i] * $mul;
259
                        $mul = $mul == 3 ? 1 : 3;
265
                        $mul = $mul == 3 ? 1 : 3;
260
                }
266
                }
261
                return 10 - ($sum % 10);
267
                return 10 - ($sum % 10);
262
        }
268
        }
263
 
269
 
Line 282... Line 288...
282
 
288
 
283
                return strlen($a) - strlen($b);
289
                return strlen($a) - strlen($b);
284
        }
290
        }
285
 
291
 
286
        /**
292
        /**
287
         * @param $to
293
         * @param OIDplusObject|string $to
288
         * @return int|null
294
         * @return int|null
289
         */
295
         */
290
        public function distance($to) {
296
        public function distance($to) {
291
                if (!is_object($to)) $to = OIDplusObject::parse($to);
297
                if (!is_object($to)) $to = OIDplusObject::parse($to);
292
                if (!$to) return null;
298
                if (!$to) return null;