Skip to content

Commit 6b9a79a

Browse files
committed
Add isPhone method, fixes jenssegers#41
1 parent f74033f commit 6b9a79a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,20 @@ $browser = $agent->browser();
129129

130130
### Desktop detection
131131

132-
Check if the user is a desktop.
132+
Check if the user is using a desktop device.
133133

134134
```php
135135
$agent->isDesktop();
136136
```
137137

138+
### Phone detection
139+
140+
Check if the user is using a phone device.
141+
142+
```php
143+
$agent->isPhone();
144+
```
145+
138146
*This checks if a user is not a mobile device, tablet or robot.*
139147

140148
### Robot detection

src/Agent.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ public function isDesktop($userAgent = null, $httpHeaders = null)
224224
return (! $this->isMobile() && ! $this->isTablet() && ! $this->isRobot());
225225
}
226226

227+
/**
228+
* Check if the device is a mobile phone.
229+
*
230+
* @param string $userAgent deprecated
231+
* @param array $httpHeaders deprecated
232+
* @return bool
233+
*/
234+
public function isPhone($userAgent = null, $httpHeaders = null)
235+
{
236+
return ($this->isMobile() && ! $this->isTablet());
237+
}
238+
227239
/**
228240
* Get the robot name.
229241
*

tests/AgentTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,21 @@ public function testDesktop()
177177
{
178178
$agent->setUserAgent($ua);
179179
$this->assertTrue($agent->isDesktop(), $ua);
180+
$this->assertFalse($agent->isMobile(), $ua);
180181
}
181182

182183
foreach($this->robots as $ua => $robot)
183184
{
184185
$agent->setUserAgent($ua);
185186
$this->assertFalse($agent->isDesktop(), $ua);
187+
$this->assertFalse($agent->isMobile(), $ua);
186188
}
187189

188190
foreach($this->devices as $ua => $device)
189191
{
190192
$agent->setUserAgent($ua);
191193
$this->assertFalse($agent->isDesktop(), $ua);
194+
$this->assertTrue($agent->isMobile(), $ua);
192195
}
193196
}
194197

0 commit comments

Comments
 (0)