Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@Blackskyliner
Copy link
Contributor

The current replacer does not cover all cases to remove declare statements regarding 'strict_types' definitions.

Currently not covered:

  • If there is more than one line break before the declare statement
  • If there are arbitrary spaces within the declare statement
  • If there is a comment before the declare statement

To not build the whole statemachine by ourself I decided to use a regex to tackle those problems. As this will in most cases only be ran if the boostrap needs to be regenerated we should be safe with the implied performance hit regarding the usage of regex here.

Rundown on the Regex parts:

  • ^ - Match the beginning of the file only
  • (<\?php)? - Match starting PHP Tags (if existent)
  • ([\s]*/\*\*?.*?\*/[\s]*)? - Match file comments (if existent)
  • [\s]* - Match arbitrary number of spaces
  • (declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)? - Match strict definition (if existent)

This should handle the whole pretty cleanup more gracefully regarding external/vendored codebases which may not apply to some predefined CodingStandard.

The current replacer does not cover all cases to remove declare statements regarding 'strict_types' definitions.

Currently not covered:
* If there is more than one line break before the declare statement
* If there are arbitrary spaces within the declare statement
* If there is a comment before the declare statement

To not build the whole statemachine by ourself I decided to use a regex to tackle those problems. As this will in most cases only be ran if the boostrap needs to be regenerated we should be safe with the implied performance hit regarding the usage of regex here.

Rundown on the Regex parts:

* `^` - Match the beginning of the file only
* `(<\?php)?` - Match starting PHP Tags (if existent)
* `([\s]*/\*\*?.*?\*/[\s]*)?` - Match file comments (if existent)
* `[\s]*` - Match arbitrary number of spaces
* `(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?` - Match strict definition (if existent)

This should handle the whole pretty cleanup more gracefully regarding external/vendored codebases which may not apply to some predefined CodingStandard.
@Blackskyliner Blackskyliner changed the title Replace substr in getCode() to cover more cases. WIP: Replace substr in getCode() to cover more cases. Jul 12, 2017
@Blackskyliner
Copy link
Contributor Author

Not throughly tested as its broken atm. and it removes too much

Because of the multiline modifier we matched everything within the whole file and not just from beginning. This resulted in removing all comments and whitespaces -- whoops!
@Blackskyliner Blackskyliner changed the title WIP: Replace substr in getCode() to cover more cases. Replace substr in getCode() to cover more cases. Jul 12, 2017
@GrahamCampbell
Copy link
Member

Thanks! Please could you also add a test case that oreviously failed, but now passes?

@Blackskyliner
Copy link
Contributor Author

Tests were added and I also found a missing spacing part in the regex.

@Blackskyliner
Copy link
Contributor Author

Hey there, I don't want to rush you, but could you do a review and merge this upstream so I can use this library directly instead of patching my composer.json with my patch repository/branch?

@GrahamCampbell GrahamCampbell merged commit 69e7735 into ClassPreloader:master Sep 9, 2017
@GrahamCampbell
Copy link
Member

Thanks. 👍

@GrahamCampbell
Copy link
Member

Just tagged 3.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.