-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Use index based string access for substr with length of 1 #8054
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
Conversation
6f4251f to
8b0b44a
Compare
| if (isset($params['root'])){ | ||
| $root = $params['root']; | ||
| if (substr($root, 0, 1) !== '/'){ | ||
| if ($root[0] !== '/'){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not 100% the same.
substr('', 0, 1) === ''but
$a = '';
$a[0];fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you should then first check if it is actually set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked all cases and added this only to the ones, that needed it. In this case there is always something in the string. See the code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise just use strpos($root, '/') !== 0
| } | ||
|
|
||
| if (substr($this->root, -1, 1) !== '/') { | ||
| if ($this->root[strlen($this->root) - 1] !== '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also rtrim? More obvious what it does?
| break; | ||
| } | ||
| if(substr($firstVersion, 0, 1) === '>') { | ||
| if($firstVersion !== '' && $firstVersion[0] === '>') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do strpos, I think its better and more obvious
8b0b44a to
6e441d6
Compare
Codecov Report
@@ Coverage Diff @@
## master #8054 +/- ##
============================================
- Coverage 51.71% 51.71% -0.01%
+ Complexity 25437 25430 -7
============================================
Files 1599 1599
Lines 95272 95264 -8
Branches 1376 1376
============================================
- Hits 49270 49265 -5
+ Misses 46002 45999 -3
|
|
I improved a bit the overall code flow. Please have another look at it. |
6e441d6 to
0a1371d
Compare
|
This is now ready for review. @nickvergessen @ChristophWurst @blizzz |
| $this->root = '/' . $this->root; | ||
| } | ||
| if (substr($this->root, -1, 1) !== '/') { | ||
| if ($this->root[strlen($this->root) - 1] !== '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->root = rtrim($this->root, '/') . '/';
lib/private/Archive/TAR.php
Outdated
| public function addFolder($path) { | ||
| $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); | ||
| if (substr($path, -1, 1) != '/') { | ||
| if (substr($path, -1) !== '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$path = rtrim($path, '/') . '/';
lib/private/Archive/TAR.php
Outdated
| } else { | ||
| $folderPath = $path; | ||
| if (substr($folderPath, -1, 1) != '/') { | ||
| if (substr($folderPath, -1) !== '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$folderPath = rtrim($folderPath, '/') . '/';0a1371d to
00b2954
Compare
|
@nickvergessen Addressed your comments. |
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
00b2954 to
9ff51aa
Compare
Found by PHP inspections and makes the code more readable and performant.