Skip to content

Conversation

@MorrisJobke
Copy link
Member

Found by PHP inspections and makes the code more readable and performant.

if (isset($params['root'])){
$root = $params['root'];
if (substr($root, 0, 1) !== '/'){
if ($root[0] !== '/'){
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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] !== '/') {
Copy link
Member

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] === '>') {
Copy link
Member

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

@codecov
Copy link

codecov bot commented Jan 26, 2018

Codecov Report

Merging #8054 into master will decrease coverage by <.01%.
The diff coverage is 66.66%.

@@             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
Impacted Files Coverage Δ Complexity Δ
lib/private/legacy/image.php 36.74% <0%> (ø) 208 <0> (ø) ⬇️
apps/files_external/lib/Lib/Storage/SFTP.php 0% <0%> (ø) 87 <0> (-2) ⬇️
lib/private/Installer.php 59.24% <0%> (ø) 77 <0> (ø) ⬇️
lib/private/Settings/Personal/PersonalInfo.php 0% <0%> (ø) 30 <0> (ø) ⬇️
lib/private/Files/Filesystem.php 67.79% <100%> (ø) 119 <0> (-1) ⬇️
apps/files_external/lib/Lib/Storage/OwnCloud.php 91.3% <100%> (-0.7%) 6 <0> (-1)
lib/private/Avatar.php 75.49% <100%> (ø) 54 <0> (ø) ⬇️
lib/private/Archive/TAR.php 80% <100%> (+0.13%) 62 <0> (+5) ⬆️
apps/files_external/lib/Lib/Storage/SMB.php 4.83% <100%> (-0.71%) 114 <0> (-4)
lib/private/Files/Storage/DAV.php 65.18% <100%> (-0.15%) 159 <0> (-4)
... and 3 more

@MorrisJobke
Copy link
Member Author

I improved a bit the overall code flow. Please have another look at it.

@MorrisJobke
Copy link
Member Author

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] !== '/') {
Copy link
Member

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, '/') . '/';

public function addFolder($path) {
$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
if (substr($path, -1, 1) != '/') {
if (substr($path, -1) !== '/') {
Copy link
Member

Choose a reason for hiding this comment

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

$path = rtrim($path, '/') . '/';

} else {
$folderPath = $path;
if (substr($folderPath, -1, 1) != '/') {
if (substr($folderPath, -1) !== '/') {
Copy link
Member

Choose a reason for hiding this comment

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

$folderPath = rtrim($folderPath, '/') . '/';

@MorrisJobke
Copy link
Member Author

@nickvergessen Addressed your comments.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
@rullzer rullzer added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jan 26, 2018
@MorrisJobke MorrisJobke merged commit 4c38d1e into master Jan 26, 2018
@MorrisJobke MorrisJobke deleted the substr-use-index branch January 26, 2018 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release Ready to be released and/or waiting for tests to finish technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants