-
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); | ||
|
|
||
| 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
Collaborator
Author
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. I want to catch only Exceptions thrown by SimpleXMLElement, not TypeError 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.
✏️ Learnings added
|
||
| $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.