Skip to content

Commit

Permalink
Merging Fix: Method annotations are in the wrong place serbanghita#913
Browse files Browse the repository at this point in the history
  • Loading branch information
serbanghita committed Feb 5, 2023
2 parents 2c353e2 + f33d505 commit dfe5300
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
6 changes: 4 additions & 2 deletions scripts/dump_magic_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

use Detection\MobileDetect;

$detect = new MobileDetect;
require_once __DIR__ . '/../src/MobileDetect.php';

$detect = new MobileDetect();

/**
* Dump all methods (+ extended)
* Use this script to generate comments like "@method bool isiPhone()"
* php -a examples/dump_magic_methods.php > methods.txt
* php export/dump_magic_methods.php > methods.txt
*/
foreach ($detect->getRules() as $name => $regex) {
echo "is$name()\n";
Expand Down
48 changes: 24 additions & 24 deletions src/MobileDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
* @author: Victor Stanciu <[email protected]> (original author)
*
* @version 3.74.0
*
*/
namespace Detection;

use BadMethodCallException;

/**
* Auto-generated isXXXX() magic methods.
* php -a export/dump_magic_methods.php
* php export/dump_magic_methods.php
*
* @method bool isiPhone()
* @method bool isBlackBerry()
Expand Down Expand Up @@ -212,12 +217,7 @@
* @method bool isWebKit()
* @method bool isConsole()
* @method bool isWatch()
*/
namespace Detection;

use BadMethodCallException;

class MobileDetect
{
/**
Expand Down Expand Up @@ -829,19 +829,19 @@ class MobileDetect
* Construct an instance of this class.
*
* @param array|null $headers Specify the headers as injection. Should be PHP _SERVER flavored.
* If left empty, will use the global _SERVER['HTTP_*'] vars instead.
* If left empty, will use the global _SERVER['HTTP_*'] vars instead.
* @param string|null $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT
* from the $headers array instead.
* from the $headers array instead.
*/
public function __construct(array $headers = null, string $userAgent = null)
public function __construct(array $headers = null, $userAgent = null)
{
$this->setHttpHeaders($headers);
$this->setUserAgent($userAgent);
}

/**
* Get the current script version.
* This is useful for the demo file,
* This is useful for the demo.php file,
* so people can check on what version they are testing
* for mobile devices.
*
Expand Down Expand Up @@ -944,7 +944,7 @@ public function getUaHttpHeaders(): array
*
* @param array|null $cfHeaders List of HTTP headers
*
* @return boolean If there were CloudFront headers to be set
* @return bool If there were CloudFront headers to be set
*/
public function setCfHeaders(array $cfHeaders = null): bool
{
Expand Down Expand Up @@ -1038,7 +1038,7 @@ public function getMatchingRegex(): ?string
return $this->matchingRegex;
}

public function getMatchesArray(): ?string
public function getMatchesArray(): ?array
{
return $this->matchesArray;
}
Expand Down Expand Up @@ -1168,10 +1168,10 @@ public function __call(string $name, array $arguments)
/**
* Find a detection rule that matches the current User-agent.
*
* @param null $userAgent deprecated
* @return boolean
* @param string|null $userAgent deprecated
* @return bool
*/
protected function matchDetectionRulesAgainstUA($userAgent = null): bool
protected function matchDetectionRulesAgainstUA(string $userAgent = null): bool
{
// Begin general search.
foreach ($this->getRules() as $_regex) {
Expand All @@ -1194,7 +1194,7 @@ protected function matchDetectionRulesAgainstUA($userAgent = null): bool
*
* @param string $key
*
* @return boolean
* @return bool
*/
protected function matchUAAgainstKey(string $key): bool
{
Expand All @@ -1219,11 +1219,11 @@ protected function matchUAAgainstKey(string $key): bool
/**
* Check if the device is mobile.
* Returns true if any type of mobile device detected, including special ones
* @param null $userAgent deprecated
* @param null $httpHeaders deprecated
* @param string|null $userAgent deprecated
* @param array|null $httpHeaders deprecated
* @return bool
*/
public function isMobile($userAgent = null, $httpHeaders = null): bool
public function isMobile(string $userAgent = null, array $httpHeaders = null): bool
{

if ($httpHeaders) {
Expand Down Expand Up @@ -1287,8 +1287,8 @@ public function isTablet(string $userAgent = null, array $httpHeaders = null): b
* @param string|null $userAgent deprecated
* @param array|null $httpHeaders deprecated
* @return bool
*@todo: The httpHeaders part is not yet used.
*
* @todo: The httpHeaders part is not yet used.
*/
public function is(string $key, string $userAgent = null, array $httpHeaders = null): bool
{
Expand All @@ -1313,13 +1313,13 @@ public function is(string $key, string $userAgent = null, array $httpHeaders = n
* This method will be used to check custom regexes against
* the User-Agent string.
*
* @param $regex
* @param string $regex
* @param string|null $userAgent
* @return bool
*
* @todo: search in the HTTP headers too.
*/
public function match($regex, string $userAgent = null): bool
public function match(string $regex, string $userAgent = null): bool
{
if (!\is_string($userAgent) && !\is_string($this->userAgent)) {
return false;
Expand Down Expand Up @@ -1355,8 +1355,8 @@ public static function getProperties(): array
* @param string $ver The string version, like "2.6.21.2152";
*
* @return float
*@todo Remove the error suppression from str_replace() call.
*
* @todo Remove the error suppression from str_replace() call.
*/
public function prepareVersionNo(string $ver): float
{
Expand Down

0 comments on commit dfe5300

Please sign in to comment.