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

strong typing, refactoring #1596

Merged
merged 29 commits into from
Oct 27, 2017
Merged

strong typing, refactoring #1596

merged 29 commits into from
Oct 27, 2017

Conversation

mimmi20
Copy link
Member

@mimmi20 mimmi20 commented Sep 23, 2017

I added strong typing to most of the functions and removed most of the setters and getters and the fluid interfaces. Additional to that I did some refactorings.

Because of the refactorings I had to write more unittests.

This PR is required for PR #1520 and PR #1579.

Fixes #1585
Fixes #1586
Fixes #1587

@mimmi20 mimmi20 added this to the Wishlist milestone Sep 23, 2017
@mimmi20 mimmi20 self-assigned this Sep 23, 2017
@codecov
Copy link

codecov bot commented Sep 23, 2017

Codecov Report

Merging #1596 into master will increase coverage by 0.3%.
The diff coverage is 90.06%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #1596     +/-   ##
===========================================
+ Coverage     44.75%   45.06%   +0.3%     
- Complexity      753      791     +38     
===========================================
  Files          1542     1553     +11     
  Lines         52276    52418    +142     
  Branches      21305    21305             
===========================================
+ Hits          23397    23623    +226     
+ Misses        28879    28795     -84
Flag Coverage Δ Complexity Δ
#full 40.71% <ø> (ø) 0 <ø> (ø) ⬇️
#lite 1.56% <ø> (ø) 0 <ø> (ø) ⬇️
#standard 22.09% <ø> (ø) 0 <ø> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
src/Browscap/Data/Division.php 100% <ø> (ø) 10 <0> (ø) ⬇️
src/Browscap/Command/BuildCommand.php 35.71% <0%> (ø) 3 <0> (ø) ⬇️
src/Browscap/Generator/Helper/BuildHelper.php 96.73% <100%> (-0.2%) 11 <0> (ø)
src/Browscap/Filter/CustomFilter.php 100% <100%> (+6.25%) 7 <7> (ø) ⬇️
src/Browscap/Formatter/PhpFormatter.php 100% <100%> (+9.37%) 13 <13> (-1) ⬇️
src/Browscap/Data/Helper/CheckDeviceData.php 100% <100%> (ø) 9 <9> (?)
src/Browscap/Writer/Factory/PhpWriterFactory.php 100% <100%> (+100%) 1 <1> (ø) ⬇️
src/Browscap/Data/Platform.php 100% <100%> (ø) 6 <5> (+1) ⬆️
src/Browscap/Formatter/XmlFormatter.php 100% <100%> (+3.12%) 13 <13> (-1) ⬇️
src/Browscap/Filter/FullFilter.php 100% <100%> (+7.69%) 6 <6> (ø) ⬇️
... and 58 more

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 f3f7d6a...588e21c. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 23, 2017

Codecov Report

Merging #1596 into master will increase coverage by 0.23%.
The diff coverage is 97.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1596      +/-   ##
============================================
+ Coverage     46.74%   46.98%   +0.23%     
+ Complexity      776      711      -65     
============================================
  Files          1569     1575       +6     
  Lines         53606    53491     -115     
  Branches      21845    21845              
============================================
+ Hits          25060    25132      +72     
+ Misses        28546    28359     -187
Flag Coverage Δ Complexity Δ
#full 42.76% <ø> (ø) 0 <ø> (ø) ⬇️
#lite 1.53% <ø> (ø) 0 <ø> (ø) ⬇️
#standard 24.41% <ø> (ø) 0 <ø> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
src/Browscap/Data/Division.php 100% <ø> (ø) 9 <0> (-1) ⬇️
src/Browscap/Browscap.php 100% <ø> (ø) 1 <0> (ø) ⬇️
src/Browscap/Command/BuildCommand.php 34.48% <0%> (-1.24%) 4 <3> (+1)
src/Browscap/Formatter/XmlFormatter.php 100% <100%> (+3.12%) 13 <13> (-1) ⬇️
src/Browscap/Data/Device.php 100% <100%> (+25%) 3 <2> (ø) ⬇️
...rc/Browscap/Data/Validator/PropertiesValidator.php 100% <100%> (ø) 16 <16> (?)
src/Browscap/Data/Factory/DivisionFactory.php 100% <100%> (ø) 5 <5> (?)
src/Browscap/Data/Factory/EngineFactory.php 100% <100%> (+33.33%) 9 <9> (+2) ⬆️
src/Browscap/Data/PropertyHolder.php 100% <100%> (ø) 27 <27> (-5) ⬇️
...c/Browscap/Writer/Factory/FullPhpWriterFactory.php 100% <100%> (ø) 3 <3> (+1) ⬆️
... and 51 more

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 fdd5327...86672cf. Read the comment docs.

@mimmi20 mimmi20 assigned jaydiablo and asgrim and unassigned mimmi20 Sep 24, 2017
@mimmi20 mimmi20 modified the milestones: Wishlist, 6025 Sep 24, 2017
@jaydiablo
Copy link
Contributor

@mimmi20 is this ready to be looked at?

@mimmi20
Copy link
Member Author

mimmi20 commented Sep 28, 2017

Yes

$json = json_decode($fileContent, true);

if (null === $json) {
throw new \RuntimeException('File "' . $filename . '" had invalid JSON.');
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be helpful here to include the JSON error triggered by the json_decode call in this exception message: http://php.net/manual/en/function.json-last-error-msg.php

Copy link
Member Author

Choose a reason for hiding this comment

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

error message is added now

/**
* @param array $useragentData
* @param array $versions
* @param array %$allDivisions
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find documentation of this, but I assume the % here is to indicate that the param is passed by reference?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should have been a &, but it is is removed now.

}

if (false === mb_strpos($useragentData['userAgent'], '#')
&& in_array($useragentData['userAgent'], $allDivisions)
Copy link
Contributor

Choose a reason for hiding this comment

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

And to that note, does $allDivisions need to be passed by reference?

This appears to be the only place it's used in this method, and it shouldn't be getting modified by an in_array call. Am I missing some other use of it here where passing by reference is necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

refernce removed

}

/**
* returns the Type of the filter
*
* @return string
*/
public function getType()
public function getType() : string
{
return 'FULL';
Copy link
Contributor

Choose a reason for hiding this comment

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

You turned the csv, ini, asp strings into constants on the FormatterInterface class, should a similar thing be done with these strings as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{
return [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this data provider removed? Are these values checked elsewhere?

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 function returns true independend of the value of the parameters. So I dont think we need a test provider.

Copy link
Contributor

@jaydiablo jaydiablo left a comment

Choose a reason for hiding this comment

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

Overall I think this looks good. Though, should we get another pair of eyes on it? @asgrim ?

}

/**
* returns the Type of the filter
*
* @return string
*/
public function getType()
public function getType() : string
{
return 'CUSTOM';
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps another case where a constant should be used?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for constant

Copy link
Member

@asgrim asgrim left a comment

Choose a reason for hiding this comment

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

Full of BC breaks (mostly elimination of fluid interfaces) which need to be documented

@@ -80,7 +80,7 @@
* A storage variable of the pattern ids covered by tests for a specific file (set when processing of that
* file begins)
*
* @var string[]
* @var array
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather be more specific about the contents of this: string[] is better (if that's what it is)

@@ -42,6 +41,8 @@ class BuildCommand extends Command

/**
* Configures the current command.
*
* @return void
Copy link
Member

Choose a reason for hiding this comment

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

Don't need this phpdoc at all really

$input->getOption('resources'),
$buildFolder
);
$version = $input->getArgument('version');
Copy link
Member

Choose a reason for hiding this comment

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

Why declare this? It doesn't seem to be used anywhere except on L102..

/**
* @return \Psr\Log\LoggerInterface $logger
* @param string $version
* @param \Psr\Log\LoggerInterface $logger
Copy link
Member

Choose a reason for hiding this comment

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

Don't need to use fully qualified class name here (LoggerInterface is already imported)

{
return $this->logger;
$this->logger = $logger;
$this->generationDate = new \DateTime();
Copy link
Member

Choose a reason for hiding this comment

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

Could we use \DateTimeImmutable? 🤔

}

/**
* returns the Type of the filter
*
* @return string
*/
public function getType()
public function getType() : string
{
return 'CUSTOM';
Copy link
Member

Choose a reason for hiding this comment

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

+1 for constant

@@ -83,7 +79,7 @@ public function isOutputSection(array $section)
*
* @return bool
*/
public function isOutputProperty($property, ?WriterInterface $writer = null)
public function isOutputProperty(string $property, ?WriterInterface $writer = null) : bool
Copy link
Member

Choose a reason for hiding this comment

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

Ideally squash out optional deps; if it's not "required" just create a DummyWriter which does nothing for example

$this->buildFolder = $this->checkDirectoryExists($buildFolder);
$this->logger = $logger;
$this->writerCollection = $writerCollection;
$this->collectionCreator = new CollectionCreator($logger);
Copy link
Member

Choose a reason for hiding this comment

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

Should also be injected (even if optional with this as default)

$realDirectory = realpath($directory);

if (false === $realDirectory) {
throw new \Exception('The directory "' . $directory . '" does not exist, or we cannot access it');
Copy link
Member

Choose a reason for hiding this comment

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

Throw a more specific exception please (even \RuntimeException is better)

}

if (!is_dir($realDirectory)) {
throw new \Exception('The path "' . $realDirectory . '" did not resolve to a directory');
Copy link
Member

Choose a reason for hiding this comment

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

Throw a more specific exception please (even \RuntimeException is better)

@asgrim asgrim modified the milestones: 6025, 6026, 6027 Oct 4, 2017
@mimmi20
Copy link
Member Author

mimmi20 commented Oct 9, 2017

@asgrim Where should the BC breaks be documented? Readme.md?

@asgrim
Copy link
Member

asgrim commented Oct 9, 2017

Yes please

@jaydiablo
Copy link
Contributor

What is the public API of this project?

Currently there's no mention in the docs of how to use the code in this project outside of the CLI commands (unless I missed something), though this PR does add some code examples for custom builds.

Since this project's primary purpose is to build the data files (and this is primarily done through CLI commands or the integration tests) should there be much of a public API, and if so, shouldn't that be documented?

@asgrim
Copy link
Member

asgrim commented Oct 9, 2017

The public API is basically only used by the website to generate the files, AFAIK; mainly big breaks should be documented for my sanity ;)

@mimmi20
Copy link
Member Author

mimmi20 commented Oct 10, 2017

@jaydiablo @asgrim Please review again.

README.md Outdated

## Changes

* The tests for integration testing the source files are splitted from the other tests
Copy link
Contributor

Choose a reason for hiding this comment

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

splitted should be split

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

README.md Outdated
## Changes

* The tests for integration testing the source files are splitted from the other tests
* Tests on travis use the build pipiline now
Copy link
Contributor

Choose a reason for hiding this comment

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

Type-o on pipiline here (should be pipeline)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

README.md Outdated
the CLI commands
----------------

There is actaully only one cli command available.
Copy link
Contributor

Choose a reason for hiding this comment

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

Another type-o here (actually).

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

README.md Outdated
- `version` (required) the name of the version that should be built
- `output` (optional) the directory where the files should be created
- `resources` (optional) the directory where the sources for the build are located
- `coverage` (optional) if this option is set, during the build a coverage file is created
Copy link
Contributor

Choose a reason for hiding this comment

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

This description isn't entirely correct.

By specifying this param, the pattern ids used for coverage reporting are added to the INI files, but no coverage is actually generated (since tests have to run to collect coverage info).

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed (I hope)

declare(strict_types = 1);
namespace Browscap\Generator;

class DirectoryMissingException extends \InvalidArgumentException
Copy link
Contributor

Choose a reason for hiding this comment

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

You have this exception class, and "NoDirectoryException" below, don't they mean the same thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

the other exception is renamed

declare(strict_types = 1);
namespace Browscap\Generator;

class NoDirectoryException extends \InvalidArgumentException
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the other exception that I mention above.

}

if (!is_dir($realDirectory)) {
throw new NoDirectoryException('The path "' . $realDirectory . '" did not resolve to a directory');
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, here's the usage of this.

I'd name this one "NotADirectoryException" or "NotDirectoryException" or something like that. "NoDirectory" could mean the same thing as the one above.

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed

@mimmi20
Copy link
Member Author

mimmi20 commented Oct 20, 2017

@jaydiablo @asgrim Please review again.

@jaydiablo
Copy link
Contributor

I noticed a couple of small type-os/grammar changes in the readme that I missed earlier. I can comment on those.

As far as the rest of the PHP changes, I was going to leave that to @asgrim, since he had requested changes earlier.

@mimmi20
Copy link
Member Author

mimmi20 commented Oct 27, 2017

Build is ok now.

@asgrim
Copy link
Member

asgrim commented Oct 27, 2017

Perfect, thanks @mimmi20, nice work here :)

@asgrim asgrim merged commit f84976f into browscap:master Oct 27, 2017
@mimmi20 mimmi20 deleted the strong-typing branch October 27, 2017 08:41
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.

None yet

3 participants