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

Add setText to Items + small AsciiArt fix #153

Merged
merged 19 commits into from
May 15, 2018
Merged

Add setText to Items + small AsciiArt fix #153

merged 19 commits into from
May 15, 2018

Conversation

Lynesth
Copy link
Collaborator

@Lynesth Lynesth commented May 15, 2018

Allow to call ->setText() directly on items to modify their content on the fly.
Can be usefull to do stuff like this:

->addItem('On', function($menu) {
    $item = $menu->getSelectedItem();
    $text = $item->getText() === 'On'
        ? 'Off'
        : 'On';
    $item->setText($text);
});

Also fixes when right spaces on AsciiArt caused it to overflow and fallback to alt text (and a test to look after it).
Example:

/* Style with 10 width */
->AsciiArtItem('XXX              ', AsciiArtItem::POSITION_CENTER, 'alt'); // This would cause 'alt' to be printed

@Lynesth Lynesth requested a review from AydinHassan May 15, 2018 14:22
@codecov-io
Copy link

codecov-io commented May 15, 2018

Codecov Report

Merging #153 into master will increase coverage by 0.11%.
The diff coverage is 86.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #153      +/-   ##
============================================
+ Coverage     95.85%   95.96%   +0.11%     
- Complexity      425      431       +6     
============================================
  Files            27       27              
  Lines          1303     1315      +12     
============================================
+ Hits           1249     1262      +13     
+ Misses           54       53       -1
Impacted Files Coverage Δ Complexity Δ
src/MenuItem/MenuMenuItem.php 86.66% <0%> (-13.34%) 7 <1> (+1)
src/MenuItem/SelectableItem.php 100% <100%> (ø) 5 <1> (+1) ⬆️
src/MenuItem/LineBreakItem.php 100% <100%> (ø) 10 <1> (+1) ⬆️
src/MenuItem/StaticItem.php 100% <100%> (ø) 10 <1> (+1) ⬆️
src/MenuItem/AsciiArtItem.php 100% <100%> (ø) 16 <2> (+2) ⬆️
src/MenuItem/SplitItem.php 100% <0%> (+2.58%) 42% <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 9ac14b7...483eaeb. Read the comment docs.

/**
* Set the raw string of text
*/
public function setText(string $text) : void;
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be on the interface, when you are changing the text you will know what item you are dealing with and therefore will know the methods, no need to change this.

/**
* Nothing to set with SplitItem
*/
public function setText(string $text) : void
Copy link
Member

Choose a reason for hiding this comment

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

Can remove this after removing from the interface.

@@ -375,6 +375,14 @@ public function testGetTextThrowsAnException() : void

(new SplitItem([]))->getText();
}

public function testSetTextThrowsAnException() : void
Copy link
Member

Choose a reason for hiding this comment

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

Can also remove this.

@AydinHassan AydinHassan merged commit 5909ec5 into master May 15, 2018
@AydinHassan AydinHassan deleted the add-set-text branch May 15, 2018 15:23
@AydinHassan AydinHassan added this to the 3.0 milestone May 16, 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