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
Support short names #107
Support short names #107
Conversation
1efe2ce
to
57aca0c
Compare
src/DataObjectAnnotator.php
Outdated
// Because the tests re-instantiate the class every time | ||
// We need to make it a unique array | ||
// Also, it's not a bad practice, making sure the array is unique | ||
self::$extension_classes = array_unique(self::$extension_classes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps move the array_unique()
to the setter and use the setter here instead, helps keep expected data more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although valid point, moving it to the setter is not ideal, because it would call the unique method for every class that is attempted to add...
What about a in_array() check? It would result in the same outcome, but the addition not being done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, that's fine too
$mixinName = "\\$fieldName"; | ||
if (Config::inst()->get(DataObjectAnnotator::class, 'use_short_name')) { | ||
$mixinName = ClassInfo::shortName($fieldName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be replaced with getAnnotationClassName($mixinName);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, missed that one :D it was a refactor after-thought, it's "implement idea" and then "think about idea", as per my usual train of thought :D
cb4ae25
to
7310c36
Compare
*/ | ||
protected function getAnnotationClassName($class) | ||
{ | ||
if (Config::inst()->get(DataObjectAnnotator::class, 'use_short_name')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just DataObjectAnnotator::config()->get('use_short_name');
now - although that may just be preference but you do save 9 characters each time! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point :) Yeps, I'll need to adjust that :)
88b9c33
to
7fc689a
Compare
16d63f4
to
ad36665
Compare
b7f2f64
to
85899b8
Compare
5391415
to
c855dbe
Compare
I think this PR is ready now. |
i hope this get merged soon, the whitespace issue is really annoying :-) |
Ping @robbieaverill @flamerohr Will rebase asap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall! I've left a couple of phpdoc related comments to fix up and some unrelated side comments for future consideration
@@ -29,6 +29,7 @@ | |||
"require-dev": { | |||
"scriptfusion/phpunit-immediate-exception-printer": "^1", | |||
"phpunit/phpunit": "^5.7", | |||
"silverstripe/recipe-cms": "~1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to require the CMS module than the recipe for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is specifically for require-dev
, basically, get the Page
class stuff installed in Travis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather not have this fixed at this point, could look in to it at a later point. Travis seems to not work the same way I work around this "issue" as CircleCI does
src/DataObjectAnnotator.php
Outdated
*/ | ||
public function __construct() | ||
{ | ||
// Don't instantiate anything if annotations are not enabled. | ||
if (static::config()->get('enabled') === true && Director::isDev()) { | ||
$this->extend('beforeDataObjectAnnotator', $this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to pass $this
- it can be accessed as $this->owner
from extension instances
src/DataObjectAnnotator.php
Outdated
|
||
/** | ||
* Add another extension class | ||
* @param $extension_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the type - string?
src/DataObjectAnnotator.php
Outdated
if ($pos !== false) { | ||
if (class_exists($className)) { | ||
$exploded = explode("\\", $className); | ||
$classNameNew = end($exploded); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use ClassInfo::shortName($className)
to do this
src/DataObjectAnnotator.php
Outdated
/** | ||
* Named `setup` to not clash with the actual setter | ||
* | ||
* @param $extension_classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no argument for this annotation
src/Extensions/Annotatable.php
Outdated
@@ -77,9 +82,19 @@ public function setUp() | |||
/** | |||
* @param $message | |||
*/ | |||
public function displayMessage($message) | |||
public function displayMessage($message, $heading = false, $end = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHPDoc needs updating, is also missing a type for $message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, yeah. Since I worked outside the "working directory" all the automatic PHPStorm annotations are missing :/
src/Generators/OrmTagGenerator.php
Outdated
*/ | ||
protected function generateManyManyTags() | ||
{ | ||
$this->generateTagsForDataLists($this->getClassConfig('many_many'), ManyManyList::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this method need to be updated, or a new one added, to support ManyManyThroughList?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's from the rebased version, right? The generateTagsForDataLists method takes care of the optional through
// @todo get it to work properly. Seems something is wrong with the installation of the CMS | ||
// We do need the CMS and the pages for proper testing | ||
if (!class_exists('\\Page')) { | ||
require_once(BASE_PATH . '/mysite/code/Page.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to get this of this code - in SS 4.2 this is in /app/src/Page.php
by default, but we should be able to rely on the PSR-0 autoloader definition. Unrelated to this PR though.
Also unrelated, but require_once is a construct rather than a function so doesn't need brackets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it doesn't require brackets, and I agree it needs to go out.
But both are not high prio for me, unless actively developing on this module, it would not hurt anyone (yet).
The require_once not needing brackets is true, I guess it's a personal preference to use the brackets, for me that is. It just feels... "more right"
AnnotatorPageTest::class => Director::baseFolder() . DIRECTORY_SEPARATOR . 'ideannotator' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'mock' . DIRECTORY_SEPARATOR . 'AnnotatorPageTest.php', | ||
AnnotatorPageTestController::class => Director::baseFolder() . DIRECTORY_SEPARATOR . 'ideannotator' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'mock' . DIRECTORY_SEPARATOR . 'AnnotatorPageTest.php', | ||
TeamSupporter::class => Director::baseFolder() . DIRECTORY_SEPARATOR . 'ideannotator' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'mock' . DIRECTORY_SEPARATOR . 'DataObjectAnnotatorTest_TeamSupporter.php', | ||
Team::class => Director::baseFolder() . DIRECTORY_SEPARATOR . 'ideannotator' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'mock' . DIRECTORY_SEPARATOR . 'DataObjectAnnotatorTest_Team.php', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an opportunity here to re-use and shorten the line length by using some variables (unrelated to this PR though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks like this would be an area that needs updating for the module to be made into a silverstripe-vendormodule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for now, I agree it would be nice to clear out properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing runs on the base of the module not living in the vendor folder. Which is okay, as the tests produce the same output, just with a different path. Very low priority for me
public function testSetExtensionClasses() | ||
{ | ||
$classes = DataObjectAnnotator::getExtensionClasses(); | ||
unset($classes[20]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers! 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, could not find a proper way around it when doing the initial work and left it to that :D
c855dbe
to
443b7f6
Compare
Fix low-prio bug with too much trimming Fix #68 simplify config calls
a76175a
to
b34dcfb
Compare
@robbieaverill @flamerohr @lekoala I think I've covered all major painpoints in this PR now. Rather have this in sooner than later, and address the leftovers in a separate PR. The pain points this PR fixes are more important than being extremely picky about what is and isn't right, in my opinion. |
@Firesphere I suggest an issue to list the remaining painpoints and get it in, things look fine as is :) I'm not a big fan of leavign |
@flamerohr I use I agree it's not the best of practices, but it works very well for me, so I'd rather leave them in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -23,11 +23,12 @@ before_script: | |||
- composer install --prefer-dist | |||
- composer require --prefer-dist --no-update silverstripe/recipe-core:1.0.x-dev | |||
- composer require --prefer-dist --no-update squizlabs/php_codesniffer:* | |||
- vendor/bin/sake dev/build flush=all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't required
@@ -168,18 +261,18 @@ protected function writeFileContent($className) | |||
$filePath = $classInfo->getClassFilePath(); | |||
|
|||
if (!is_writable($filePath)) { | |||
// Unsure how to test this properly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the issue of direct output in build tasks (and related operations) 😆 you can test this in one of two ways:
- Buffer the output of the test
- Move the call to
DB::alterati...
into a class method, then partially mock it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the make-path-unwritable-mid-operation is what I'm referring to ;)
Any further thoughts @flamerohr @zanderwar ? |
any idea when this will be merged? :-) it's really annoying to have the white line removed |
Adding support for short classnames and updating the docs accordingly.
This works via a config, that gets the short classname to prevent IDE's from mentioning "Unnecessary FQN"
Included is a fix for a whitespace trim introduced in rc-1
Resolves #108 , SQN instead of FQN