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

auto-generate some properties #1826

Merged
merged 6 commits into from
Mar 23, 2018
Merged

auto-generate some properties #1826

merged 6 commits into from
Mar 23, 2018

Conversation

mimmi20
Copy link
Member

@mimmi20 mimmi20 commented Feb 25, 2018

With this PR the following properties are removed from the source files and genererated during the build process

  • Browser_Type
  • Crawler
  • isSyndicationReader
  • Device_Type
  • isTablet
  • isMobileDevice

Additional to that in the source files the strings "true" and "false" were changed to the boolean values true or false, some integer properties (e.g. Browser_Bits, CssVersion) have been converted to int.

The Models and Tests have been updated for this. Some missing tests were added too.

This PR should fix #1433.

@mimmi20 mimmi20 added this to the 6028 milestone Feb 25, 2018
@codecov
Copy link

codecov bot commented Feb 25, 2018

Codecov Report

Merging #1826 into master will increase coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1826      +/-   ##
============================================
+ Coverage     49.09%   49.14%   +0.04%     
+ Complexity      764      758       -6     
============================================
  Files          1642     1642              
  Lines         59624    59749     +125     
  Branches      26683    26683              
============================================
+ Hits          29275    29364      +89     
- Misses        30349    30385      +36
Flag Coverage Δ Complexity Δ
#full 43.58% <ø> (ø) 0 <ø> (ø) ⬇️
#lite 1.76% <ø> (ø) 0 <ø> (ø) ⬇️
#standard 25.2% <ø> (ø) 0 <ø> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
src/Browscap/Data/Expander.php 65.94% <0%> (-13.69%) 63% <0%> (+6%)
...rc/Browscap/Data/Validator/PropertiesValidator.php 100% <0%> (ø) 2% <0%> (-14%) ⬇️
src/Browscap/Data/Factory/DeviceFactory.php 100% <0%> (ø) 2% <0%> (+1%) ⬆️
src/Browscap/Data/PropertyHolder.php 100% <0%> (ø) 27% <0%> (-2%) ⬇️
src/Browscap/Data/Device.php 100% <0%> (ø) 4% <0%> (+1%) ⬆️
src/Browscap/Data/DataCollection.php 100% <0%> (+10%) 23% <0%> (ø) ⬇️
src/Browscap/Data/Factory/BrowserFactory.php 100% <0%> (+12.5%) 4% <0%> (+1%) ⬆️
src/Browscap/Data/Browser.php 100% <0%> (+60%) 5% <0%> (+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 0433036...3a2146d. Read the comment docs.

@mimmi20 mimmi20 mentioned this pull request Feb 25, 2018
{
$this->type = $type;
Copy link
Member

Choose a reason for hiding this comment

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

What values can type be?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do want just a list of these types, or do you want a proper validation?

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 object is a simple data container. The validation has to be setup in the factory.

Copy link
Member

Choose a reason for hiding this comment

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

Data should be validated as it enters the place of usage (i.e. the class), rather than assume it is validated somewhere else; that's why value objects are useful; encapsulate validation of values in a value object, make it immutable so it can never accidentally become invalid (if you want to change the value, you create a new object always), and there is implicit trust that the value object is in a consistent, valid and invariant state.
Specifically in this case, it was a question really: is $type really an enumeration? Can the value be validated?

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 added the validation for the type property in the factory, like all other validation we do.

The type property is not really an enum. The possible values are limited by the external libraries I created and used here and by the validation browscap-php does.

{
$this->type = $type;
Copy link
Member

Choose a reason for hiding this comment

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

Same - do no validation done here to check $type is valid

@asgrim asgrim removed this from the 6028 milestone Mar 2, 2018
@mimmi20
Copy link
Member Author

mimmi20 commented Mar 19, 2018

@asgrim @jaydiablo Could you review this again?

*/
public function testBuildWithWrongDeviceType() : void
{
$this->expectException(\UnexpectedValueException::class);
Copy link
Member

Choose a reason for hiding this comment

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

Just a minor nitpick, but ideally expectException* should be just before where the exception happens, rather than at the start of the method. No need to change anything here, but just maybe more logical :)

@asgrim asgrim self-assigned this Mar 23, 2018
@asgrim asgrim added this to the 6.0.29 milestone Mar 23, 2018
@asgrim
Copy link
Member

asgrim commented Mar 23, 2018

Thanks @mimmi20 👍

@asgrim asgrim merged commit cd4ad0c into browscap:master Mar 23, 2018
@mimmi20 mimmi20 deleted the issue-1433 branch March 23, 2018 18:50
@mimmi20
Copy link
Member Author

mimmi20 commented Mar 23, 2018

Thanks

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.

Remove deprecated properties from tests?
2 participants