Closed Bilge closed 4 years ago
I will add the following test to make sure $matches
doesn't persist.
/** @test */
public function matches_does_not_persit_across_multiple_calls()
{
$this->CrawlerDetect->isCrawler('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)');
$matches = $this->CrawlerDetect->getMatches();
$this->assertEquals($this->CrawlerDetect->getMatches(), 'monitoring', $matches);
$this->CrawlerDetect->isCrawler('This should not match');
$matches = $this->CrawlerDetect->getMatches();
$this->assertNull($this->CrawlerDetect->getMatches());
}
Rather than first writing matches to a temporary variable, we write them directly to the class member variable. This eliminates the temporary
$matches
variable and also the temporary$result
variable.Note that we also eliminated the
if
statement which is intentional because it is this author's belief that it is incorrect for two reasons:$matches
are saved; if the method is called then$matches
should always be updated rather than persist the result from a previous call.