-
Notifications
You must be signed in to change notification settings - Fork 1
introduce md tryMention #3
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
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.
@MBoretto Nice work!
I noted a few suggestions above.
class User extends Entity | ||
{ | ||
/** | ||
* Try mention |
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.
Would be great if the description were more... descriptive 😉
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.
will do
src/Entities/User.php
Outdated
if ($this->username === null) { | ||
if ($this->last_name !== null) { | ||
return $this->first_name . ' ' . $this->last_name; | ||
if (isset($this->username)) { |
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.
Instead of using $this->whatever
, the way it works no is to use $this->getProperty('whatever')
, as that checks if the value exists / is null
.
To make it easier, just set $username = $this->getProperty('username');
, then use the $username
variable. Same applies for other properties.
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.
make sense
src/Entities/User.php
Outdated
$string = str_replace('[', '\[', $string); | ||
$string = str_replace('`', '\`', $string); | ||
$string = str_replace('*', '\*', $string); | ||
return str_replace('_', '\_', $string); |
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.
Instead of calling str_replace
multiple times, they can all be combined into 1 call:
return str_replace(
['[', '`', '*', '_'],
['\[', '\`', '\*', '\_'],
$string
);
If you want to play with regex, here a 1-liner 😇 :
return preg_replace('/([\[`\*_])/', '\\\\$1', $string);
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.
it's the same but i am more confident with str replace
src/Entities/User.php
Outdated
* | ||
* @return string | ||
*/ | ||
public function prependAt($string) |
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.
Not sure it makes sense to have an own method for this, as it's being used just 2x and is just prepending a character.
Could you explain why you opted for a separate method?
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.
just to be more clear but can be removed of course no big deal
src/Entities/User.php
Outdated
* | ||
* @return string | ||
*/ | ||
public function stripMarkDown($string) |
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 be static, as it doesn't access any class members. Would also save you from creating a User
object in the tests.
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 prefer to not create a static class just for this, al least not now. In this pr i keep everything in this file but I think that this method can be put on top, maybe in the entity class in order to share it with all the entities. What do you think?
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.
Great idea @ putting it in the entities class!
Hello! This is a feature/bugfix that I would like to push in the next version.
I build this on top of your entities refactoring to test your work. If you prefer I can create another pr that point to longman/develop. Let me know