public function testDeviceDetector() { $testUA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 Version/8.0.4 Safari/600.4.10'; $detector = DeviceDetectorFactory::getInstance($testUA); $this->assertEquals('Safari', $detector->getClient()['name']); $this->assertSame($detector, DeviceDetectorFactory::getInstance($testUA)); DeviceDetectorFactory::clearInstances(); $this->assertNotSame($detector, DeviceDetectorFactory::getInstance($testUA)); }
/** * @param TrackingVisit $visit * @param string $ua * * @SuppressWarnings(PHPMD.NPathComplexity) * because of ternary operators which in current case is clear enough to replace it with 'if' statement. */ protected function processUserAgentString(TrackingVisit $visit, $ua) { $device = $this->deviceDetector->getInstance($ua); $os = $device->getOs(); if (is_array($os)) { $visit->setOs(isset($os['name']) ? $os['name'] : null); $visit->setOsVersion(isset($os['version']) ? $os['version'] : null); } $client = $device->getClient(); if (is_array($client)) { $visit->setClient(isset($client['name']) ? $client['name'] : null); $visit->setClientType(isset($client['type']) ? $client['type'] : null); $visit->setClientVersion(isset($client['version']) ? $client['version'] : null); } $visit->setDesktop($device->isDesktop()); $visit->setMobile($device->isMobile()); $visit->setBot($device->isBot()); }