Skip to content

Commit

Permalink
Merge pull request amphp#4 from spatie/analysis-zeoRO7
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
freekmurze authored Nov 3, 2017
2 parents 93306bf + a0af7c8 commit e0e9179
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/Dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Spatie\Dns;

use Exception;
use Spatie\Dns\Exceptions\InvalidArgument;
use Symfony\Component\Process\Process;
use Spatie\Dns\Exceptions\InvalidArgument;

class Dns
{
Expand All @@ -17,7 +17,7 @@ class Dns
'SOA',
'MX',
'TXT',
'DNSKEY'
'DNSKEY',
];

public function __construct(string $domain)
Expand All @@ -29,15 +29,15 @@ public function __construct(string $domain)
$this->domain = $this->sanitizeDomainName($domain);
}

public function getRecords(... $types): string
public function getRecords(...$types): string
{
$types = $this->determineTypes($types);

$types = count($types)
? $types
: $this->recordTypes;

$dnsRecords = array_map(function($type) {
$dnsRecords = array_map(function ($type) {
return $this->getRecordsOfType($type);
}, $types);

Expand All @@ -55,7 +55,7 @@ protected function determineTypes(array $types): array
}, $types);

foreach ($types as $type) {
if (!in_array($type, $this->recordTypes)) {
if (! in_array($type, $this->recordTypes)) {
throw InvalidArgument::filterIsNotAValidRecordType($type, $this->recordTypes);
}
}
Expand All @@ -74,13 +74,13 @@ protected function sanitizeDomainName(string $domain): string

protected function getRecordsOfType(string $type): string
{
$command = 'dig +nocmd ' . escapeshellarg($this->domain) . " {$type} +multiline +noall +answer";
$command = 'dig +nocmd '.escapeshellarg($this->domain)." {$type} +multiline +noall +answer";

$process = new Process($command);

$process->run();

if (!$process->isSuccessful()) {
if (! $process->isSuccessful()) {
throw new Exception('Dns records could not be fetched');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InvalidArgument extends InvalidArgumentException
{
public static function domainIsMissing()
{
return new static("A domain name is required");
return new static('A domain name is required');
}

public static function filterIsNotAValidRecordType($filter, $validRecordTypes)
Expand All @@ -17,4 +17,4 @@ public static function filterIsNotAValidRecordType($filter, $validRecordTypes)

return new static("The given filter `{$filter}` is not valid. It should be one of {$recordTypeString}");
}
}
}
13 changes: 6 additions & 7 deletions tests/DnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Spatie\Dns\Test;

use PHPUnit\Framework\TestCase;
use Spatie\Dns\Dns;
use PHPUnit\Framework\TestCase;
use Spatie\Dns\Exceptions\InvalidArgument;

class DnsTest extends TestCase
{
/** @var \Spatie\Dns\Dns */
/** @var \Spatie\Dns\Dns */
protected $dns;

protected function setUp()
Expand Down Expand Up @@ -61,7 +61,6 @@ public function it_fetches_records_for_the_types_in_a_given_array()
$this->assertDontSeeRecordTypes($records, ['A']);
}


/** @test */
public function it_doesnt_care_about_casing()
{
Expand All @@ -84,9 +83,9 @@ public function it_throws_an_exception_if_an_invalid_record_type_is_passed()

protected function assertSeeRecordTypes($records, $type)
{
$types = (array)$type;
$types = (array) $type;

foreach($types as $type) {
foreach ($types as $type) {
//some dns servers use tabs, let's replace them by spaces
$records = preg_replace('/\s+/', ' ', $records);

Expand All @@ -96,9 +95,9 @@ protected function assertSeeRecordTypes($records, $type)

protected function assertDontSeeRecordTypes($records, $type)
{
$types = (array)$type;
$types = (array) $type;

foreach($types as $type) {
foreach ($types as $type) {
//some dns servers use tabs, let's replace them by spaces
$records = preg_replace('/\s+/', ' ', $records);

Expand Down

0 comments on commit e0e9179

Please sign in to comment.