Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Nov 10, 2024
1 parent f1c5109 commit c787b7e
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Address
public $tokens = [];

/**
* @param static|array $address
* @param static|string $address
*/
public function __construct($address = '')
{
Expand Down
8 changes: 0 additions & 8 deletions src/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
class Normalizer extends JString
{
/**
* normalizeAddress.
*
* @return static
*/
public function normalizeAddress()
Expand Down Expand Up @@ -49,8 +47,6 @@ public function normalizeAddress()
}

/**
* normalize.
*
* @return static
*/
public function normalize()
Expand All @@ -59,8 +55,6 @@ public function normalize()
}

/**
* digitize.
*
* @return static
*/
public function digitize()
Expand All @@ -71,8 +65,6 @@ public function digitize()
}

/**
* regularize.
*
* @return static
*/
public function regularize()
Expand Down
18 changes: 2 additions & 16 deletions src/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@

class Point
{
/**
* $x.
*
* @var int
*/
/** @var int */
public $x = 0;

/**
* $y.
*
* @var int
*/
/** @var int */
public $y = 0;

/**
* __construct.
*
* @param int $x
* @param int $y
*/
Expand All @@ -31,8 +21,6 @@ public function __construct($x = 0, $y = 0)
}

/**
* empty.
*
* @return bool
*/
public function isEmpty()
Expand All @@ -41,8 +29,6 @@ public function isEmpty()
}

/**
* compare.
*
* @param string $operator
* @return bool
*/
Expand Down
76 changes: 21 additions & 55 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,19 @@

class Rule
{
/**
* $zip3.
*
* @var string
*/
/** @var string */
public $zip3;

/**
* $zip5.
*
* @var string
*/
/** @var string */
public $zip5;

/**
* $address.
*
* @var Address
*/
/** @var Address */
public $address;

/**
* $tokens.
*
* @var array
*/
/** @var array */
public $tokens;

/**
* __construct.
*
* @param string $rule
*/
public function __construct($rule)
Expand All @@ -54,8 +36,6 @@ public function __construct($rule)
}

/**
* zip5.
*
* @return string
*/
public function zip5()
Expand All @@ -64,8 +44,6 @@ public function zip5()
}

/**
* zip.
*
* @return string
*/
public function zip()
Expand All @@ -74,8 +52,6 @@ public function zip()
}

/**
* zip3.
*
* @return string
*/
public function zip3()
Expand All @@ -84,8 +60,6 @@ public function zip3()
}

/**
* match.
*
* @param Address|string $address
* @return bool
*/
Expand Down Expand Up @@ -123,16 +97,16 @@ public function match($address)
($token === '以上' && $addressPoint->compare($left, '>=') === false) ||
($token === '以下' && $addressPoint->compare($left, '<=') === false) ||
($token === '' && (
($right->compare($addressPoint, '<=') && $addressPoint->compare($left, '<=')) ||
($currentTokens->includes('含附號全') === true && ($addressPoint->x === $left->x))
) === false) ||
($right->compare($addressPoint, '<=') && $addressPoint->compare($left, '<=')) ||
($currentTokens->includes('含附號全') === true && ($addressPoint->x === $left->x))
) === false) ||
($token === '含附號' && ($addressPoint->x === $left->x) === false) ||
($token === '附號全' && ($addressPoint->x === $left->x && $addressPoint->y > 0) === false) ||
($token === '及以上附號' && $addressPoint->compare($left, '>=') === false) ||
($token === '含附號以下' && (
$addressPoint->compare($left, '<=') ||
$addressPoint->x === $left->x
) === false)
$addressPoint->compare($left, '<=') ||
$addressPoint->x === $left->x
) === false)
) {
return false;
}
Expand All @@ -142,8 +116,6 @@ public function match($address)
}

/**
* tokens.
*
* @return JArray
*/
public function tokens()
Expand All @@ -152,8 +124,6 @@ public function tokens()
}

/**
* tokenize.
*
* @param string $rule
* @return array
*/
Expand All @@ -168,23 +138,22 @@ private function tokenize($rule, Closure $addressResolver)
'[連至單雙全](?=[\d全]|$)',
];

$addressResolver($this->normalize($rule)->replace('/'.implode('|', $pattern).'/u', function ($m) use (&$tokens) {
$token = &$m[0];
if ($token === '') {
return '';
}
$addressResolver($this->normalize($rule)->replace('/'.implode('|', $pattern).'/u',
function ($m) use (&$tokens) {
$token = &$m[0];
if ($token === '') {
return '';
}

$tokens[] = $token;
$tokens[] = $token;

return $token === '附號全' ? '' : '';
}));
return $token === '附號全' ? '' : '';
}));

return $tokens;
}

/**
* normalize.
*
* @param string $rule
* @return Normalizer
*/
Expand All @@ -208,8 +177,6 @@ private function normalize($rule)
}

/**
* normalizeAddress.
*
* @return Address
*/
private function normalizeAddress(Address $address, JArray $ruleAddressTokens)
Expand All @@ -220,16 +187,15 @@ private function normalizeAddress(Address $address, JArray $ruleAddressTokens)

return new Address(
new JArray($address->tokens()->filter(function ($token) use ($removeUnits) {
return isset($token[Address::UNIT]) === true && in_array($token[Address::UNIT], $removeUnits, true) === false;
return isset($token[Address::UNIT]) === true && in_array($token[Address::UNIT], $removeUnits,
true) === false;
})->map(function ($token) {
return implode('', $token);
}))
);
}

/**
* equalsToken.
*
* @param JArray $ruleAddressTokens
* @param JArray $addressTokens
* @param int $cur
Expand Down
4 changes: 0 additions & 4 deletions src/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Rules
private $storage;

/**
* __construct.
*
* @param Storage $storage
*/
public function __construct(Storage $storage = null)
Expand All @@ -25,8 +23,6 @@ public function __construct(Storage $storage = null)
}

/**
* match.
*
* @param Address|string $address
* @return string|void
*/
Expand Down
Loading

0 comments on commit c787b7e

Please sign in to comment.