11<?php
22/**
3- * Copyright (C) 2015 Derek J. Lambert
3+ * Copyright (C) 2016 Derek J. Lambert
44 *
55 * Permission is hereby granted, free of charge, to any person obtaining a copy
66 * of this software and associated documentation files (the "Software"), to deal
@@ -41,11 +41,6 @@ class Parser
4141 */
4242 private $ input ;
4343
44- /**
45- * @var Lexer
46- */
47- private $ lexer ;
48-
4944 /**
5045 * @var int
5146 */
@@ -56,28 +51,45 @@ class Parser
5651 */
5752 private $ nextSymbol ;
5853
54+ /**
55+ * @var Lexer
56+ */
57+ private $ lexer ;
58+
5959 /**
6060 * Constructor
6161 *
6262 * Setup up instance properties
6363 *
64- * @param string $input
64+ * @param string|null $input
6565 */
66- public function __construct ($ input )
66+ public function __construct ($ input = null )
6767 {
68- // Save input string for use in messages
69- $ this ->input = $ input ;
70- // Create new Lexer and tokenize input string
71- $ this ->lexer = new Lexer ($ input );
68+ $ this ->lexer = new Lexer ();
69+
70+ if (null !== $ input ) {
71+ $ this ->input = $ input ;
72+ }
7273 }
7374
7475 /**
7576 * Parse input string
7677 *
78+ * @param string|null $input
79+ *
7780 * @return float|int|array
7881 */
79- public function parse ()
82+ public function parse ($ input = null )
8083 {
84+ if (null !== $ input ) {
85+ $ this ->input = $ input ;
86+ }
87+
88+ $ this ->nextCardinal = null ;
89+ $ this ->nextSymbol = null ;
90+
91+ $ this ->lexer ->setInput ($ this ->input );
92+
8193 // Move Lexer to first token
8294 $ this ->lexer ->moveNext ();
8395
@@ -315,7 +327,7 @@ private function minutes()
315327 }
316328
317329 // Get fractional minutes
318- $ minutes = $ minutes / 60 ;
330+ $ minutes /= 60 ;
319331
320332 // Match minutes symbol
321333 $ this ->symbol ();
@@ -346,7 +358,7 @@ private function seconds()
346358 }
347359
348360 // Get fractional seconds
349- $ seconds = $ seconds / 3600 ;
361+ $ seconds /= 3600 ;
350362
351363 // Match seconds symbol if requirement not colon
352364 if (Lexer::T_COLON !== $ this ->nextSymbol ) {
@@ -430,7 +442,7 @@ private function cardinal($value)
430442
431443 // Throw exception if value is out of range
432444 if ($ value > $ range ) {
433- throw $ this ->rangeError ('Degrees ' , $ range , ( -1 * $ range) );
445+ throw $ this ->rangeError ('Degrees ' , $ range , -1 * $ range );
434446 }
435447
436448 // Return value with sign
0 commit comments