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

Enable include_paths #16

Merged
merged 3 commits into from
Oct 14, 2015
Merged

Enable include_paths #16

merged 3 commits into from
Oct 14, 2015

Conversation

jacooobi
Copy link
Contributor

@jacooobi jacooobi commented Oct 2, 2015

As listed in spec

$dir = rtrim($dir, '\\/');

foreach (scandir($dir) as $f) {
if (in_array("$prefix$f", $this->config["exclude_paths"])) {
if (!isset($this->config['include_paths']) && in_array("$prefix$f", $this->config["exclude_paths"])) {
Copy link

Choose a reason for hiding this comment

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

I get why this works but it took me a minute. I appreciate the desire to reuse the file expansion logic, but is there a way to do it without having to resort to checks like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm while it's not the most optimal solution, it allows for a nice code reuse, just like you noticed.
I am not super comfortable with php so it is unlikely I will come up with anything better. Although, if you guys have a better design in mind, I could try to reimplement it with your guidance.

Copy link

Choose a reason for hiding this comment

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

How about passing in the exclusions as an array when you call queuePaths? That way the exclude_paths-based option could pass in $this->config["exclude_paths"], while the include-paths-based option could pass in an empty array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delayed reply. To be honest I am not sure if I got your idea right. How would the include_paths be handled if I pass an empty array? It's worth mentioning that at the moment, an engine decides to expand include_paths when this config value is not empty and the way CLI works after the recent changes is that it translates exclude_paths to include_paths.
As a result include_paths are the ones always getting expanded.

Copy link

Choose a reason for hiding this comment

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

Really my design criticism is that it seems that queuePaths has too much responsibility. By this time we enter queuePaths, we've already decided whether we're using includes or excludes, so checking for them here again just makes the code harder to read.

So, my suggestion was, if you want to make queuePaths reusable, you could take exclusions in the argument list:

public function queuePaths($dir, $prefix = '', $exclusions = []) {

And remove the explicit references to $this->config in line 50:

if (in_array("$prefix$f", $exclusions)) {

Which means that you could use this for exclude-based file building this way:

$this->queuePaths($dir, $prefix, $this->config['exclude_paths'])

But for include-based file building you could leave line 32 as:

$this->queuePaths("/code$f", "$f/");

In that case, $exclusions will simply be an empty array, and will not skip any files in the directory. But you get the goal of reusing queuePaths while focusing its responsibilities.

@jacooobi
Copy link
Contributor Author

jacooobi commented Oct 6, 2015

Thanks @fhwang for your suggestions, I've modified the code.

@fhwang
Copy link

fhwang commented Oct 6, 2015

Other then the CC issues, LGTM

@jacooobi
Copy link
Contributor Author

jacooobi commented Oct 6, 2015

What are the CC issues? I can't access that page.

@ABaldwinHunter
Copy link
Contributor

@jacobi007 Hm when I click on the link to CC issues, I don't see any new ones:

screen shot 2015-10-08 at 5 37 37 pm

So I think we can disregard those for now.

Anything else blocking merging this?

@ABaldwinHunter
Copy link
Contributor

cc @codeclimate/review

foreach ($this->config['include_paths'] as $f) {
if ($f !== '.' and $f !== '..') {

if (is_dir("/code$f")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think we wrote include_paths with leading / chars. I notice you do put a / before $f on line 39. I'm guessing this has been tested, but just checking it's intentional.

@wfleming
Copy link
Contributor

wfleming commented Oct 8, 2015

Yeah, the code climate issues thing is a bug on our end. I've seen it before. 😢

@mxie
Copy link
Contributor

mxie commented Oct 14, 2015

Looks good based from some testing.

mxie added a commit that referenced this pull request Oct 14, 2015
@mxie mxie merged commit 255e681 into codeclimate:master Oct 14, 2015
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.

5 participants