Skip to content

Conversation

AydinHassan
Copy link
Member

@AydinHassan AydinHassan commented May 6, 2018

  • Extracted tests for whitespace at the end of ascii art lines to own test
  • Added test for actual ascii art
  • Strip whitespace from each line of the given test
  • Remove redundant trim and mb_strlen calls
  • Remove right padding - (I'm not really sure what that is for?)

@Lynesth could you take a look at this please

@@ -64,19 +66,16 @@ public function getRows(MenuStyle $style, bool $selected = false) : array

switch ($this->position) {
case self::POSITION_LEFT:
return $row;
Copy link
Member Author

Choose a reason for hiding this comment

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

return is done below the switch anyway.

$row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));
$padding -= ($this->artLength - $length);
$left = ceil($padding / 2);
$row = sprintf('%s%s', str_repeat(' ', $left), $row);
Copy link
Member Author

Choose a reason for hiding this comment

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

Not really sure why we added the white space on the end

);
}

public function testWithRealAsciiArtCenteredWithWhiteSpaceAtTheEndOfEachLine() : void
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the test for your end whitespace fix

Copy link
Collaborator

Choose a reason for hiding this comment

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

Much sexier than the one I made eh :)

@codecov-io
Copy link

codecov-io commented May 6, 2018

Codecov Report

Merging #105 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #105      +/-   ##
============================================
- Coverage     96.68%   96.66%   -0.02%     
  Complexity      293      293              
============================================
  Files            22       22              
  Lines           904      900       -4     
============================================
- Hits            874      870       -4     
  Misses           30       30
Impacted Files Coverage Δ Complexity Δ
src/MenuItem/AsciiArtItem.php 100% <100%> (ø) 14 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c0b307...6dc3436. Read the comment docs.

break;
case self::POSITION_RIGHT:
$row = rtrim($row);
$padding = $padding - ($this->artLength - mb_strlen($row));
$padding -= ($this->artLength - $length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those can be removed. The padding is simply equal to

$padding = $style->getContentWidth() - $this->artLength;

and can be moved out of the array_map (line 65).

Moreover the $length doesn't need to be calculated (you made everything so it's based on the longest row) so you can remove line 63 too (can't comment on it).

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice. works perfect.

$left = ceil($padding/2);
$right = $padding - $left;
$row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));
$padding -= ($this->artLength - $length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be remove too.

@Lynesth
Copy link
Collaborator

Lynesth commented May 7, 2018

That's a good idea ;)

@AydinHassan
Copy link
Member Author

@Lynesth requested changes made!

@AydinHassan AydinHassan merged commit 50eb732 into master May 7, 2018
@AydinHassan AydinHassan deleted the ascii-art-refactor branch May 7, 2018 08:11
@AydinHassan AydinHassan added this to the 3.0 milestone May 7, 2018
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.

3 participants