Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Hhvm strict #280

Merged
merged 44 commits into from
Dec 21, 2017
Merged

Hhvm strict #280

merged 44 commits into from
Dec 21, 2017

Conversation

everton-rosario
Copy link
Contributor

This PR

  • Transforms code into strict HHVM
  • Adds more tests to cover
  • Fixes whatever needed to

everton-rosario and others added 23 commits October 29, 2017 23:16
All Element classes converted and tests passing, running on HHVM
Fixed Validators
Covered Clients
All Element classes converted and tests passing, running on HHVM
Fixed Validators
Covered Clients
Finished Getters
Treating Rules and Transformer
All Element classes converted and tests passing, running on HHVM
Fixed Validators
Covered Clients
Finished Getters
Treating Rules and Transformer
*/
public function toDOMElement($document = null)
public function toDOMElement(\DOMDocument $document): \DOMNode
Copy link
Contributor

Choose a reason for hiding this comment

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

$document was optional before. Should it stay this way?
I think toDOMElement(\DOMDocument $document = new \DOMDocument()) would have the same semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically the main issue of us rendering the elements and creating by ourselves the DOMDocument, is that we will miss the correct encoding to write content to.
I feel that keeping it optional (so we create it all the time) works well only for test purposes, but for practical usage of our lib, we should drop this being optional.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good

*/
public function toDOMElement($document = null)
public function toDOMElement(\DOMDocument $document): \DOMNode
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -32,14 +32,10 @@ public static function create()
*
* @param \DOMDocument $document - The document where this element will be appended (optional).
*
* @return \DOMElement
Copy link
Contributor

Choose a reason for hiding this comment

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

Are DOMElement and DOMNode the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically all DOMElement is a DOMNode, but not the other way around.

While parsing a DOMDocument and navigating through the children elements, only standard tags will map to DOMElement.

*
* @return $this
*/
public function withAttribute($attribute)
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this moved somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

This method already exists on AbstractGetter, so after the refactor you can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @diegoquinteiro says.
Removed for no needing to keep it here.

Copy link
Contributor

@diegoquinteiro diegoquinteiro left a comment

Choose a reason for hiding this comment

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

Hey @everton-rosario, thank you so much for putting this port together - it is a LOT of work and it looks great!

Please look at my comments, I've scanned through all the changes and pointed out some problems.

From all the comments, the most important concerns for me are:

  • Can we get the performance optimizations back to the Transformer?
  • Why did we change the test case input/outputs? For example, the WP rules were changed a lot, so we're not sure we're being backwards compatible.
  • Why did we come back with InteractiveInsideParagraphRule?

Let me know if you wanna discuss any point!

Thanks one more time =)

@@ -22,29 +21,25 @@ class Client
/**
* @var Facebook The main Facebook service client.
*/
private $facebook;
private \Facebook\Facebook $facebook;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason why we dropped use Facebook\Facebook;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Namespace conflicts for autoload =(

*/
protected $pageID;
protected string $pageID;

/**
* @var bool|false Are we using the Instant Articles development sandbox?
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use bool only instead of bool|false, as bool contains false. We would use false if we knew the variable couldn't be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, changing.

$facebook = new Facebook([
'app_id' => $appID,
'app_secret' => $appSecret,
'default_access_token' => $accessToken,
'default_graph_version' => 'v2.5'
]);

return new static($facebook, $pageID, $developmentMode);
return new self($facebook, $pageID, $developmentMode);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion on this particular instance, but just want to make sure you know that self will point always to Client, even if it's extended. So if:

class SubClass extends Client { ... }

SubClass::create(...); // will create a Client, not a SubClass

Where using static:

class SubClass extends Client { ... }

SubClass::create(...); // will create a SubClass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For strict code, this is the error:

Can't use new static() for Facebook\InstantArticles\Client\Client; __construct arguments are not guaranteed to be consistent in child classes This declaration neither defines an abstract/final __construct nor uses <<__ConsistentConstruct>> attribute : src/Facebook/InstantArticles/Client/Client.php:17

// Never try to take live if we're in development (the API would throw an error if we tried)
$published = $this->developmentMode ? false : $published;

// Assume default access token is set on $this->facebook
$response = $this->facebook->post($this->pageID . Client::EDGE_NAME, [
'html_source' => $article->render(null, $formatOutput),
'html_source' => $article->render(),
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're not using $formatOutput anymore, we should remove the parameter of the method or add a deprecation notice to the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filling a issue so we treat correctly the charset encoding.
We don't have a good formatter into HHVM also, so we will need to fix this as well.

2 new issues: #281 #282

$field = $this->developmentMode ? 'development_instant_article' : 'instant_article';

$response = $this->facebook->get('?id=' . $canonicalURL . '&fields=' . $field);
$instantArticle = $response->getGraphNode()->getField($field);

if (!$instantArticle) {
return null;
return -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

We could still return null if we changed the return type to ?int, right? Returning -1 seems a little bit obscure to me (and code would not fail fast), but if you absolutely need to use -1, please update the phpdoc comment of the method accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch.
Fixing.

$log->debug('rule: '.get_class($this));
$log->debug('-------');
}
// if ($matches_context && $matches_node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's get rid of all these commented lines =)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also create an issue for adding proper verbosity levels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed: #285

*
* @return string The full qualified name of class.
*/
public function getObjClassName(): string
Copy link
Contributor

Choose a reason for hiding this comment

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

How is that different from getClassName()? If it's a leftover, let's get rid of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately using //strict it forces to call each method properly.
so self::getClassName() and $instance->getObjClassName() are required for code =(

*/
private $rules = [];
private array<Rule> $rules = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do a project wide search for array< to review outdated documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍
Fixed know ones.

@@ -97,82 +91,42 @@ public static function markAsProcessed($node)
*
* @param DOMNode $node The node to clone
Copy link
Contributor

Choose a reason for hiding this comment

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

Outdated docs as well, let's change it to:

/**
 * @param DOMNode The node of interest
 * @return bool Whether the node is processed or not
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -231,27 +185,12 @@ public function transform($context, $node)
}
$matched = false;

// Get all classes and interfaces this context extends/implements
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing the performance optimization? The algorithm is 10 times slower without it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The changes you reverted on addRule, getRules and getAllClassTypes were all related to this optimization.

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 original perf PR for reference: #46

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the discussion points.
This was all broken(after strict migration), not well tested and documented. Got rid of it.
We can add it back with proper review.

@diegoquinteiro
Copy link
Contributor

:shipit:

@everton-rosario everton-rosario merged commit ad17250 into hhvm Dec 21, 2017
@everton-rosario everton-rosario deleted the hhvm_strict branch December 21, 2017 13:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants