-
Notifications
You must be signed in to change notification settings - Fork 179
declare strict_types in all files #474
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
base: v2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine; | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -nP --type=php '\bpublic function search\(\$query, array \$params = \[\]\)|\blistByQuery\(\$query, \$params\)|catch \(Exception \$e\)' src/Redmine/Api/Search.phpRepository: kbsali/php-redmine-api Length of output: 222 🏁 Script executed: cd src/Redmine/Api && cat -n Search.php | head -100Repository: kbsali/php-redmine-api Length of output: 4157 🏁 Script executed: grep -n "public function listByQuery" src/Redmine/Api/Search.php -A 2Repository: kbsali/php-redmine-api Length of output: 191 🏁 Script executed: python3 << 'EOF'
# In PHP 7.0+, TypeError is a subclass of Error, not Exception
# So catch(Exception) would NOT catch TypeError
# Let's verify this understanding is correct
print("PHP Type Hierarchy (PHP 7+):")
print("- Error (base for all errors)")
print(" - TypeError (inherits from Error, NOT Exception)")
print("- Exception (separate from Error)")
print("\nConclusion: catch(Exception) will NOT catch TypeError")
EOFRepository: kbsali/php-redmine-api Length of output: 264 Cast With Fix public function search($query, array $params = [])
{
`@trigger_error`('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::listByQuery()` instead.', E_USER_DEPRECATED);
try {
- $results = $this->listByQuery($query, $params);
+ $results = $this->listByQuery((string) $query, $params);
} catch (Exception $e) {
if ($this->getLastResponse()->getContent() === '') {
return false;🤖 Prompt for AI Agents |
||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Api; | ||
|
|
||
| use Redmine\Client\Client; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Client; | ||
|
|
||
| use Redmine\Api; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Client; | ||
|
|
||
| use Redmine\Api; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine; | ||
|
|
||
| use Throwable; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Exception; | ||
|
|
||
| use Exception; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Exception; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Exception; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Exception; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Exception; | ||
|
|
||
| use Redmine\Exception as RedmineException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Serializer; | ||
|
|
||
| use JsonException; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Serializer; | ||
|
|
||
| use Stringable; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Serializer; | ||
|
|
||
| use Exception; | ||
| use JsonException; | ||
| use Redmine\Exception\SerializerException; | ||
| use SimpleXMLElement; | ||
| use Stringable; | ||
| use Throwable; | ||
|
|
||
| /** | ||
| * XmlSerializer. | ||
|
|
@@ -75,7 +77,7 @@ private function deserialize(string $encoded): void | |
|
|
||
| try { | ||
| $this->deserialized = new SimpleXMLElement($encoded); | ||
| } catch (Throwable $e) { | ||
| } catch (Exception $e) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Narrowing catch from With
Call sites like Proposed fix: Keep catching Throwable- } catch (Exception $e) {
+ } catch (\Throwable $e) {Apply to both catch blocks at lines 80 and 129. Also applies to: 129-129 🤖 Prompt for AI Agents |
||
| $errors = []; | ||
| $code = $e->getCode(); | ||
|
|
||
|
|
@@ -123,8 +125,8 @@ private function denormalize(array $normalized): void | |
| $prevSetting = libxml_use_internal_errors(true); | ||
|
|
||
| try { | ||
| $this->deserialized = $this->createXmlElement($rootElementName, $this->normalized[$rootElementName]); | ||
| } catch (Throwable $e) { | ||
| $this->deserialized = $this->createXmlElement((string) $rootElementName, $this->normalized[$rootElementName]); | ||
| } catch (Exception $e) { | ||
| $errors = []; | ||
|
|
||
| foreach (libxml_get_errors() as $error) { | ||
|
|
@@ -196,7 +198,7 @@ private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void | |
| $array = $xml->addChild($k, ''); | ||
| $array->addAttribute('type', 'array'); | ||
| foreach ($v as $id) { | ||
| $array->addChild($specialParams[$k], $id); | ||
| $array->addChild($specialParams[$k], (string) $id); | ||
| } | ||
| } elseif (is_array($v)) { | ||
| $array = $xml->addChild($k, ''); | ||
|
|
@@ -231,7 +233,7 @@ private function attachCustomFieldXML(SimpleXMLElement $xml, array $fields, stri | |
| $_field->addAttribute('field_format', $field['field_format']); | ||
| } | ||
| if (isset($field['id'])) { | ||
| $_field->addAttribute('id', $field['id']); | ||
| $_field->addAttribute('id', strval($field['id'])); | ||
| } | ||
| if (array_key_exists('value', $field) && is_array($field['value'])) { | ||
| $_field->addAttribute('multiple', 'true'); | ||
|
|
@@ -243,7 +245,7 @@ private function attachCustomFieldXML(SimpleXMLElement $xml, array $fields, stri | |
| } else { | ||
| $_values->addAttribute('type', 'array'); | ||
| foreach ($field['value'] as $val) { | ||
| $_values->addChild('value', $val); | ||
| $_values->addChild('value', (string) $val); | ||
| } | ||
| } | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Redmine\Tests\Unit\Api; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.