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

first usages of String component #4514

Merged
merged 17 commits into from
Oct 8, 2020
Merged

first usages of String component #4514

merged 17 commits into from
Oct 8, 2020

Conversation

Guite
Copy link
Member

@Guite Guite commented Oct 6, 2020

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixed #4053
Refs tickets -
License MIT
Changelog updated no

Description

This PR introduces the String component for some string operations.

Currently the functions.php file is explicitly included to make the helper methods available (u(), b(), s()).
This inclusion can be removed again when #4352 is done because then the String component will be explicitly added by composer which adds "files": [ "Resources/functions.php" ] to the autoloader (link).

@Guite Guite added this to the 3.1.0 milestone Oct 6, 2020
@Guite Guite requested a review from craigh October 6, 2020 18:30
@craigh
Copy link
Member

craigh commented Oct 6, 2020

This inclusion can be removed again when #4352 is done because then the String component will be explicitly added by composer

why not add this to our own composer file?

@@ -132,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->verified = in_array((int) $input->getOption('verified'), [0, 1, 2]) ? (int) $input->getOption('verified') : 1;
$regDate = $input->getOption('regdate') ?? $this->nowUTC;
$this->range = is_string($regDate) && '>' === $regDate[0];
$this->regDate = $this->range ? mb_substr($regDate, 1) : $regDate;
$this->regDate = $this->range ? (string)s($regDate)->slice(1) : $regDate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after cast or no? here you do not have a space, later you do have a space.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing for casts were not consistent before already. Improved that in 7a1aa6a

@@ -88,7 +89,7 @@ public function __construct(array $json = [])
$this->dependencies = $this->formatDependencies($json);
$this->shortName = $json['extra']['zikula']['short-name'];
$this->class = $json['extra']['zikula']['class'];
$this->namespace = mb_substr($this->class, 0, mb_strrpos($this->class, '\\') + 1);
$this->namespace = (string) s($this->class)->beforeLast('\\', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space here.

Also, it seems strange to me that a component called String requires to be cast as a string... shouldn't it output a string? I know that it is returning an AbstractSting that is \Stringable, so can we lose the repeated (string) casting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Stringable interface is introduced with PHP 8. Like shown in https://symfony.com/blog/new-in-symfony-5-1-string-improvements#use-stringable-interface the Polyfill provides it already.

This will allow you to use union types such as string|Stringable in the future when you later upgrade to PHP 8.

At the moment our methods expect string for both return types and arguments. So to avoid BC breaks I added the casts in the first step. Changed them to calling __toString() now (a3e4402).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a ticket to 4.0 to change type hints to \Stringable where possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up created in #4516

@@ -73,18 +74,18 @@ public function decode(string $jsonFilePath)
{
$base = str_replace('\\', '/', dirname($jsonFilePath));
$srcPath = dirname(__DIR__, 4) . '/src/';
$base = mb_substr($base, mb_strlen($srcPath));
$base = s($base)->slice(mb_strlen($srcPath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now here you do not cast (string). It seems this should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added __toString() call in bd77d26

@Guite
Copy link
Member Author

Guite commented Oct 7, 2020

why not add this to our own composer file?

I tried that before but it seems to be ignored; probably because symfony/string is already covered by symfony/symfony. Hence, I referenced #4352

@craigh
Copy link
Member

craigh commented Oct 7, 2020

can use use StyleCI to enforce future casts to require the space?

@craigh
Copy link
Member

craigh commented Oct 7, 2020

I tried that before but it seems to be ignored; probably because symfony/string is already covered by symfony/symfony. Hence, I referenced #4352

I mean add the files requirement directly to the composer file

@Guite
Copy link
Member Author

Guite commented Oct 7, 2020

can use use StyleCI to enforce future casts to require the space?

Done in 32f350e

@Guite
Copy link
Member Author

Guite commented Oct 7, 2020

I mean add the files requirement directly to the composer file

Done in 264e51d

@Guite
Copy link
Member Author

Guite commented Oct 7, 2020

I mean add the files requirement directly to the composer file

Done in 264e51d

Needs to be changed in distribution, too.

@Guite Guite merged commit 98b2a56 into master Oct 8, 2020
@Guite Guite deleted the issue4053 branch October 8, 2020 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[General] Utilise String component
2 participants