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

Check additionally for object values which result in empty values #61

Closed
wants to merge 1 commit into from

Conversation

mmachatschek
Copy link
Contributor

This fixes #59

@codecov-io
Copy link

Codecov Report

Merging #61 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             develop    #61   +/-   ##
========================================
  Coverage        100%   100%           
- Complexity       223    227    +4     
========================================
  Files             30     30           
  Lines            597    608   +11     
========================================
+ Hits             597    608   +11
Impacted Files Coverage Δ Complexity Δ
...LOGIC/Export/Helpers/UsergroupAwareSimpleValue.php 100% <100%> (ø) 9 <0> (-1) ⬇️
src/FINDOLOGIC/Export/Helpers/DataHelper.php 100% <100%> (ø) 15 <3> (+3) ⬆️
src/FINDOLOGIC/Export/Data/Property.php 100% <100%> (ø) 11 <0> (ø) ⬇️
...IC/Export/Helpers/UsergroupAwareMultiValueItem.php 100% <100%> (ø) 6 <1> (+1) ⬆️
src/FINDOLOGIC/Export/Data/Attribute.php 100% <100%> (ø) 10 <0> (ø) ⬇️
src/FINDOLOGIC/Export/Data/Usergroup.php 100% <100%> (ø) 6 <1> (+1) ⬆️

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 f58ac67...6a307be. Read the comment docs.

@mmachatschek mmachatschek requested a review from howard June 15, 2018 09:40
*/
public static function checkForObjectType($value)
{
if (is_object($value)) {
Copy link
Contributor

@DomBra DomBra Jun 17, 2018

Choose a reason for hiding this comment

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

Just for keeping the convention:

In this method you could return is_object($value) and add it as condition for UsergroupAwareSimpleValue::validate, as already is done for DataHelper::checkForEmptyValue.

E.g.

return DataHelper::checkForEmptyValue($value) && DataHelper::checkForObjectType($value);

Copy link
Collaborator

Choose a reason for hiding this comment

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

That might be a good idea.

Also, it would be better if the method checked if the value was an acceptable one (is_string() and is_numeric()) instead of checking if it was one of, possible multiple, disallowed types.

Another thing is: What if the passed object has a useful ::__toString() method that actually returns something that is worth being exported? If there was a nice way to check this, the library's convenience could be improved, but I guess it's hard to judge if a ::__toString() method makes sense at runtime. So we can probably expect users to explicitly call it.

*/
public static function checkForObjectType($value)
{
if (is_object($value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That might be a good idea.

Also, it would be better if the method checked if the value was an acceptable one (is_string() and is_numeric()) instead of checking if it was one of, possible multiple, disallowed types.

Another thing is: What if the passed object has a useful ::__toString() method that actually returns something that is worth being exported? If there was a nice way to check this, the library's convenience could be improved, but I guess it's hard to judge if a ::__toString() method makes sense at runtime. So we can probably expect users to explicitly call it.

* @param mixed $value The value to check.
* @throw ObjectNotAllowedException In case the provided value is a object.
*/
public static function checkForObjectType($value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we change the check to check for permitted values instead of restricted ones, we should probably better call it something like checkForAcceptableType or just checkType.

@@ -10,6 +10,14 @@ public function __construct($message = 'Empty values are not allowed!')
}
}

class ObjectNotAllowedException extends \RuntimeException
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better naming would be something like UnsupportedTypeException or whatever better name you can think of, as we should change the check to check for acceptable values instead of one unacceptable one.

@@ -10,6 +10,14 @@ public function __construct($message = 'Empty values are not allowed!')
}
}

class ObjectNotAllowedException extends \RuntimeException
{
public function __construct($message = "Objects as values are not allowed!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget to update the default message. Maybe pass the value as constructor parameter, so we can dynamically build a message like <VALUE TYPE> is not an acceptable export value..

@howard
Copy link
Collaborator

howard commented Jun 17, 2018

@DomBra Thanks for taking a look as well!

@howard
Copy link
Collaborator

howard commented Nov 13, 2018

@mmachatschek Still interested in this PR? Just needs some issues being fixed and conflicts resolved.

@mmachatschek
Copy link
Contributor Author

@howard Yes, still interested. But I'll probably will make another approach. I'll close the PR at the time I'll find the time for this.

@mmachatschek
Copy link
Contributor Author

closed. Outdated. New PR following

@mmachatschek mmachatschek deleted the additional_validation_check branch December 20, 2018 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend string value validity check
4 participants