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

Support short names #107

Merged
merged 2 commits into from Jul 5, 2018
Merged

Support short names #107

merged 2 commits into from Jul 5, 2018

Conversation

Firesphere
Copy link
Member

@Firesphere Firesphere commented Feb 10, 2018

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

// 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);

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.

Copy link
Member Author

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?

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);
}

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);?

Copy link
Member Author

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

@Firesphere Firesphere force-pushed the support_short_names branch 2 times, most recently from cb4ae25 to 7310c36 Compare February 10, 2018 03:56
*/
protected function getAnnotationClassName($class)
{
if (Config::inst()->get(DataObjectAnnotator::class, 'use_short_name')) {
Copy link
Member

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! :)

Copy link
Member Author

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 :)

@Firesphere Firesphere force-pushed the support_short_names branch 3 times, most recently from 88b9c33 to 7fc689a Compare February 11, 2018 02:33
@Firesphere
Copy link
Member Author

I think this PR is ready now.

@lekoala
Copy link
Contributor

lekoala commented May 24, 2018

i hope this get merged soon, the whitespace issue is really annoying :-)

@Firesphere
Copy link
Member Author

Ping @robbieaverill @flamerohr

Will rebase asap

Copy link
Contributor

@robbieaverill robbieaverill left a 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",
Copy link
Contributor

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

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 is specifically for require-dev, basically, get the Page class stuff installed in Travis

Copy link
Member Author

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

*/
public function __construct()
{
// Don't instantiate anything if annotations are not enabled.
if (static::config()->get('enabled') === true && Director::isDev()) {
$this->extend('beforeDataObjectAnnotator', $this);
Copy link
Contributor

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


/**
* Add another extension class
* @param $extension_class
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing the type - string?

if ($pos !== false) {
if (class_exists($className)) {
$exploded = explode("\\", $className);
$classNameNew = end($exploded);
Copy link
Contributor

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

/**
* Named `setup` to not clash with the actual setter
*
* @param $extension_classes
Copy link
Contributor

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

@@ -77,9 +82,19 @@ public function setUp()
/**
* @param $message
*/
public function displayMessage($message)
public function displayMessage($message, $heading = false, $end = false)
Copy link
Contributor

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

Copy link
Member Author

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 :/

*/
protected function generateManyManyTags()
{
$this->generateTagsForDataLists($this->getClassConfig('many_many'), ManyManyList::class);
Copy link
Contributor

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?

Copy link
Member Author

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');
Copy link
Contributor

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

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 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',
Copy link
Contributor

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)

Copy link
Contributor

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

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 works for now, I agree it would be nice to clear out properly

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 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]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Magic numbers! 😆

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 know, could not find a proper way around it when doing the initial work and left it to that :D

Fix low-prio bug with too much trimming

Fix #68

simplify config calls
@Firesphere
Copy link
Member Author

@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.
The left-over pain points are also only a problem if the user is actively developing on this, instead of being a user.

@Firesphere Firesphere mentioned this pull request May 27, 2018
@flamerohr
Copy link

@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 @TODO as they have a tendency to linger forever, but that's also an option.

@Firesphere
Copy link
Member Author

@flamerohr I use // @todo actively in my PHPStorm and VSCode configuration, to show me where todo's are in case I have time to properly refactor things.

I agree it's not the best of practices, but it works very well for me, so I'd rather leave them in.

@Firesphere Firesphere added bug enhancement dev-issue Issue only affecting active developers labels May 27, 2018
Copy link
Contributor

@robbieaverill robbieaverill left a 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
Copy link
Contributor

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
Copy link
Contributor

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

Related: silverstripe/silverstripe-framework#6524

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's the make-path-unwritable-mid-operation is what I'm referring to ;)

@robbieaverill
Copy link
Contributor

Any further thoughts @flamerohr @zanderwar ?

@lekoala
Copy link
Contributor

lekoala commented Jul 5, 2018

any idea when this will be merged? :-) it's really annoying to have the white line removed

@robbieaverill robbieaverill merged commit b4a79c8 into master Jul 5, 2018
@robbieaverill robbieaverill deleted the support_short_names branch July 5, 2018 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dev-issue Issue only affecting active developers enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

keep empty lines
5 participants