Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add phpstan and fix up types #633

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ jobs:
run: composer update --prefer-dist --no-progress --no-suggest --no-interaction ${{ matrix.composer-flags }}

- run: composer run-script test

- run: composer run-script phpstan
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"mtdowling/burgomaster": "dev-master#72151eddf5f0cf101502b94bf5031f9c53501a04",
"phpunit/phpunit": "^4.8.36|^7.5.15|^9.3.10",
"php-mock/php-mock-phpunit": "^1.1|^2.1",
"sebastian/version": ">=1.0.3"
"sebastian/version": ">=1.0.3",
"phpstan/phpstan": "^1.2"
},
"autoload": {
"psr-4" : {
Expand All @@ -38,6 +39,7 @@
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan",
"test": "vendor/bin/phpunit"
},
"minimum-stability": "dev",
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: max
treatPhpDocTypesAsCertain: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
checkUnionTypes: false
paths:
- src/
6 changes: 3 additions & 3 deletions src/Breadcrumbs/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class Breadcrumb
/**
* Create a new breadcrumb instance.
*
* @param string $name the name of the breadcrumb
* @param string $type the type of breadcrumb
* @param array $metaData additional information about the breadcrumb
* @param string|null $name the name of the breadcrumb
* @param string $type the type of breadcrumb
* @param array $metaData additional information about the breadcrumb
*
* @throws \InvalidArgumentException
*
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrumbs/Recorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function rewind()
/**
* Is the current key position set?
*
* @return int
* @return bool
*/
#[\ReturnTypeWillChange]
public function valid()
Expand Down
14 changes: 8 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function getSessionTracker()
/**
* Get the Bugsnag API Key.
*
* @var string
* @return string
*/
public function getApiKey()
{
Expand Down Expand Up @@ -550,7 +550,7 @@ public function setFilters(array $filters)
*
* @deprecated Use redactedKeys instead
*
* @var string[]
* @return string[]
*/
public function getFilters()
{
Expand Down Expand Up @@ -586,7 +586,7 @@ public function setProjectRootRegex($projectRootRegex)
*
* @param string $file
*
* @return string
* @return bool
*/
public function isInProject($file)
{
Expand Down Expand Up @@ -674,7 +674,7 @@ public function setNotifier(array $notifier)
/**
* Get the notifier to report as to Bugsnag.
*
* @var string[]
* @return string[]
*/
public function getNotifier()
{
Expand Down Expand Up @@ -948,6 +948,8 @@ public function getSessionClient()
* This is an amount of bytes or 'null' to disable increasing the limit.
*
* @param int|null $value
*
* @return Configuration
*/
public function setMemoryLimitIncrease($value)
{
Expand Down Expand Up @@ -985,7 +987,7 @@ public function setDiscardClasses(array $discardClasses)
*
* This can contain both fully qualified class names and regular expressions.
*
* @var array
* @return array
*/
public function getDiscardClasses()
{
Expand All @@ -1009,7 +1011,7 @@ public function setRedactedKeys(array $redactedKeys)
/**
* Get the array of metadata keys that should be redacted.
*
* @var string[]
* @return string[]
*/
public function getRedactedKeys()
{
Expand Down
22 changes: 12 additions & 10 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ class Configuration
/**
* A client to use to send sessions.
*
* @var \GuzzleHttp\ClientInterface
* @var \GuzzleHttp\ClientInterface|null
*
* @deprecated This will be removed in the next major version.
*/
protected $sessionClient;
protected $sessionClient = null;

/**
* @var string
Expand Down Expand Up @@ -204,7 +204,7 @@ public function __construct($apiKey)
/**
* Get the Bugsnag API Key.
*
* @var string
* @return string
*/
public function getApiKey()
{
Expand Down Expand Up @@ -288,7 +288,7 @@ public function setFilters(array $filters)
*
* @deprecated Use redactedKeys instead
*
* @var string[]
* @return string[]
*/
public function getFilters()
{
Expand Down Expand Up @@ -317,7 +317,7 @@ public function setProjectRoot($projectRoot)
*/
public function setProjectRootRegex($projectRootRegex)
{
if ($projectRootRegex && @preg_match($projectRootRegex, null) === false) {
if ($projectRootRegex && @preg_match($projectRootRegex, '') === false) {
throw new InvalidArgumentException('Invalid project root regex: '.$projectRootRegex);
}

Expand All @@ -330,7 +330,7 @@ public function setProjectRootRegex($projectRootRegex)
*
* @param string $file
*
* @return string
* @return bool
*/
public function isInProject($file)
{
Expand Down Expand Up @@ -359,7 +359,7 @@ public function setStripPath($stripPath)
*/
public function setStripPathRegex($stripPathRegex)
{
if ($stripPathRegex && @preg_match($stripPathRegex, null) === false) {
if ($stripPathRegex && @preg_match($stripPathRegex, '') === false) {
throw new InvalidArgumentException('Invalid strip path regex: '.$stripPathRegex);
}

Expand Down Expand Up @@ -423,7 +423,7 @@ public function setNotifier(array $notifier)
/**
* Get the notifier to report as to Bugsnag.
*
* @var string[]
* @return string[]
*/
public function getNotifier()
{
Expand Down Expand Up @@ -804,6 +804,8 @@ public function getSessionClient()
* This is an amount of bytes or 'null' to disable increasing the limit.
*
* @param int|null $value
*
* @return $this
*/
public function setMemoryLimitIncrease($value)
{
Expand Down Expand Up @@ -843,7 +845,7 @@ public function setDiscardClasses(array $discardClasses)
*
* This can contain both fully qualified class names and regular expressions.
*
* @var array
* @return array
*/
public function getDiscardClasses()
{
Expand All @@ -867,7 +869,7 @@ public function setRedactedKeys(array $redactedKeys)
/**
* Get the array of metadata keys that should be redacted.
*
* @var string[]
* @return string[]
*/
public function getRedactedKeys()
{
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ protected function getHeaders($version = self::NOTIFY_PAYLOAD_VERSION)
/**
* Send a POST request to Bugsnag.
*
* @param string $uri the uri to hit
* @param array $data the request options
* @param string $uri the uri to hit
* @param array $options the request options
*
* @return void
*/
Expand Down
12 changes: 7 additions & 5 deletions src/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class Report
/**
* Attached session from SessionTracking.
*
* @var array
* @var array|null;
*/
protected $session;
protected $session = null;

/**
* Create a new report from a PHP error.
Expand Down Expand Up @@ -331,6 +331,8 @@ public function setSeverityReason(array $severityReason)
/**
* Sets the unhandled flag.
*
* @param bool $unhandled
*
* @return $this
*/
public function setUnhandled($unhandled)
Expand Down Expand Up @@ -637,7 +639,7 @@ public function getSummary()
/**
* Sets the session data.
*
* @return $this
* @return void
*/
public function setSessionData(array $session)
{
Expand Down Expand Up @@ -746,12 +748,12 @@ protected function exceptionObject()
* @param mixed $obj the data to cleanup
* @param bool $isMetaData if it is meta data
*
* @return array|null
* @return mixed|null
*/
protected function cleanupObj($obj, $isMetaData)
{
if (is_null($obj)) {
return;
return null;
}

if (is_array($obj)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Request/BasicResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected static function readInput()
protected static function parseInput(array $server, $input)
{
if (!$input) {
return;
return null;
}

if (isset($server['CONTENT_TYPE']) && stripos($server['CONTENT_TYPE'], 'application/json') === 0) {
Expand All @@ -142,5 +142,7 @@ protected static function parseInput(array $server, $input)

return (array) $params ?: null;
}

return null;
}
}
1 change: 1 addition & 0 deletions src/Request/ConsoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ public function getContext()
*/
public function getUserId()
{
return null;
}
}
4 changes: 2 additions & 2 deletions src/Request/NullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getMetaData()
*/
public function getContext()
{
//
return null;
}

/**
Expand All @@ -61,6 +61,6 @@ public function getContext()
*/
public function getUserId()
{
//
return null;
}
}
4 changes: 4 additions & 0 deletions src/Request/PhpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public function getContext()
if (isset($this->server['REQUEST_METHOD']) && isset($this->server['REQUEST_URI'])) {
return $this->server['REQUEST_METHOD'].' '.strtok($this->server['REQUEST_URI'], '?');
}

return null;
}

/**
Expand Down Expand Up @@ -169,5 +171,7 @@ protected function getRequestIp()
if (isset($this->server['REMOTE_ADDR'])) {
return $this->server['REMOTE_ADDR'];
}

return null;
}
}
12 changes: 12 additions & 0 deletions src/SessionTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ class SessionTracker
/**
* The current session payload version.
*
* @var string
*
* @deprecated Use {HttpClient::SESSION_PAYLOAD_VERSION} instead.
*/
protected static $SESSION_PAYLOAD_VERSION = HttpClient::SESSION_PAYLOAD_VERSION;

/**
* The amount of time between each sending attempt.
*
* @var int
*/
protected static $DELIVERY_INTERVAL = 30;

/**
* The maximum amount of sessions to hold onto.
*
* @var int
*/
protected static $MAX_SESSION_COUNT = 50;

/**
* The key for storing session counts.
*
* @var string
*/
protected static $SESSION_COUNTS_KEY = 'bugsnag-session-counts';

/**
* The key for storing last sent data.
*
* @var string
*/
protected static $SESSIONS_LAST_SENT_KEY = 'bugsnag-sessions-last-sent';

Expand Down Expand Up @@ -117,6 +127,8 @@ public function __construct(Configuration $config, HttpClient $http = null)
/**
* @param Configuration $config
*
* @return void
*
* @deprecated Change the Configuration via the Client object instead.
*/
public function setConfig(Configuration $config)
Expand Down
Loading