Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ip validator #21

Closed
wants to merge 4 commits into from
Closed

Ip validator #21

wants to merge 4 commits into from

Conversation

shoman4eg
Copy link
Contributor

Q A
Is bugfix? yes
New feature? no
Breaks BC? yes
Tests pass? yes?
Fixed issues

*
* @return Ip
*/
public function useSubnet($subnet): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd introduce two methods instead:

  • requireSubnet
  • optionalSubnet

Also internally it makes sense to introduce three private constants instead of having true/false/null as magic values.

*
* @return Ip
*/
public function useIpv4($ipv4): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function useIpv4($ipv4): self
public function allowIpv4(bool $value): self

*
* @return Ip
*/
public function useIpv6(bool $ipv6): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function useIpv6(bool $ipv6): self
public function allowIpv6(bool $value): self

{
$result = new Result();
$this->ipv6 = $ipv6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->ipv6 = $ipv6;
$this->allowIpv6 = $value;

*/
public function useIpv4($ipv4): self
{
$this->ipv4 = $ipv4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->ipv4 = $ipv4;
$this->allowIpv4 = $value;

*/
public function useSubnet($subnet): self
{
$this->subnet = $subnet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->subnet = $subnet;
$this->subnetStrategy = $subnet;

*
* @return Ip
*/
public function useNegation(bool $negation): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function useNegation(bool $negation): self
public function allowNegation(bool $value): self

*/
public function useNegation(bool $negation): self
{
$this->negation = $negation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->negation = $negation;
$this->allowNegation = $value;

}

return $result;
return $this->validateSubnet($value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes little sense to have a separate method in this case.

$validator = new Ip(['ranges' => $range]);
$this->assertEquals($expectedRange, $validator->ranges);
$validator = new Ip();
$validator->setRanges($range);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$validator->setRanges($range);
$validator->ranges($range);

@kamarton
Copy link
Contributor

Closable via #32

@samdark samdark closed this Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants