Skip to content

Commit

Permalink
Merge pull request #191 from stof/better_phpdoc
Browse files Browse the repository at this point in the history
Improve phpdoc
  • Loading branch information
stof authored Oct 24, 2019
2 parents a746433 + b71d6c6 commit dda2ee4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/Css/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Processor
* Get the rules from a given CSS-string
*
* @param string $css
* @param array $existingRules
* @param Rule[] $existingRules
*
* @return Rule[]
*/
public function getRules($css, $existingRules = array())
Expand All @@ -27,6 +28,7 @@ public function getRules($css, $existingRules = array())
* Get the CSS from the style-tags in the given HTML-string
*
* @param string $html
*
* @return string
*/
public function getCssFromStyleTags($html)
Expand All @@ -47,6 +49,7 @@ public function getCssFromStyleTags($html)

/**
* @param string $css
*
* @return string
*/
private function doCleanup($css)
Expand Down
21 changes: 13 additions & 8 deletions src/Css/Property/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
class Processor
{
/**
* Split a string into seperate properties
* Split a string into separate properties
*
* @param string $propertiesString
* @return array
*
* @return string[]
*/
public function splitIntoSeparateProperties($propertiesString)
{
Expand Down Expand Up @@ -40,8 +41,9 @@ public function splitIntoSeparateProperties($propertiesString)
}

/**
* @param $string
* @return mixed|string
* @param string $string
*
* @return string
*/
private function cleanup($string)
{
Expand All @@ -58,9 +60,10 @@ private function cleanup($string)
}

/**
* Convert a property-string into an object
* Converts a property-string into an object
*
* @param string $property
*
* @return Property|null
*/
public function convertToObject($property, Specificity $specificity = null)
Expand All @@ -82,9 +85,10 @@ public function convertToObject($property, Specificity $specificity = null)
}

/**
* Convert an array of property-strings into objects
* Converts an array of property-strings into objects
*
* @param string[] $properties
*
* @param array $properties
* @return Property[]
*/
public function convertArrayToObjects(array $properties, Specificity $specificity = null)
Expand All @@ -106,7 +110,8 @@ public function convertArrayToObjects(array $properties, Specificity $specificit
/**
* Build the property-string for multiple properties
*
* @param array $properties
* @param Property[] $properties
*
* @return string
*/
public function buildPropertiesString(array $properties)
Expand Down
4 changes: 2 additions & 2 deletions src/Css/Property/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class Property

/**
* Property constructor.
* @param $name
* @param $value
* @param string $name
* @param string $value
* @param Specificity|null $specificity
*/
public function __construct($name, $value, Specificity $specificity = null)
Expand Down
26 changes: 17 additions & 9 deletions src/Css/Rule/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
class Processor
{
/**
* Split a string into seperate rules
* Splits a string into separate rules
*
* @param string $rulesString
* @return array
*
* @return string[]
*/
public function splitIntoSeparateRules($rulesString)
{
Expand All @@ -22,6 +23,7 @@ public function splitIntoSeparateRules($rulesString)

/**
* @param string $string
*
* @return string
*/
private function cleanup($string)
Expand All @@ -39,11 +41,12 @@ private function cleanup($string)
}

/**
* Convert a rule-string into an object
* Converts a rule-string into an object
*
* @param string $rule
* @param int $originalOrder
* @return array
*
* @return Rule[]
*/
public function convertToObjects($rule, $originalOrder)
{
Expand Down Expand Up @@ -74,11 +77,13 @@ public function convertToObjects($rule, $originalOrder)
}

/**
* Calculate the specificity based on a CSS Selector string,
* Calculates the specificity based on a CSS Selector string,
* Based on the patterns from premailer/css_parser by Alex Dunae
*
* @see https://github.com/premailer/css_parser/blob/master/lib/css_parser/regexps.rb
*
* @param string $selector
*
* @return Specificity
*/
public function calculateSpecificityBasedOnASelector($selector)
Expand Down Expand Up @@ -118,7 +123,9 @@ public function calculateSpecificityBasedOnASelector($selector)
}

/**
* @param array $rules
* @param string[] $rules
* @param Rule[] $objects
*
* @return Rule[]
*/
public function convertArrayToObjects(array $rules, array $objects = array())
Expand All @@ -133,12 +140,13 @@ public function convertArrayToObjects(array $rules, array $objects = array())
}

/**
* Sort an array on the specificity element in an ascending way
* Sorts an array on the specificity element in an ascending way
* Lower specificity will be sorted to the beginning of the array
*
* @param Rule $e1 The first element.
* @param Rule $e2 The second element.
*
* @return int
* @param Rule $e1 The first element.
* @param Rule $e2 The second element.
*/
public static function sortOnSpecificity(Rule $e1, Rule $e2)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Css/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TijsVerkoyen\CssToInlineStyles\Css\Rule;

use Symfony\Component\CssSelector\Node\Specificity;
use TijsVerkoyen\CssToInlineStyles\Css\Property\Property;

final class Rule
{
Expand All @@ -12,7 +13,7 @@ final class Rule
private $selector;

/**
* @var array
* @var Property[]
*/
private $properties;

Expand Down Expand Up @@ -55,7 +56,7 @@ public function getSelector()
/**
* Get properties
*
* @return array
* @return Property[]
*/
public function getProperties()
{
Expand Down
6 changes: 6 additions & 0 deletions src/CssToInlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct()
*
* @param string $html
* @param string $css
*
* @return string
*/
public function convert($html, $css = null)
Expand All @@ -54,6 +55,7 @@ public function convert($html, $css = null)
*
* @param \DOMElement $element
* @param Css\Property\Property[] $properties
*
* @return \DOMElement
*/
public function inlineCssOnElement(\DOMElement $element, array $properties)
Expand Down Expand Up @@ -88,6 +90,7 @@ public function inlineCssOnElement(\DOMElement $element, array $properties)
* Get the current inline styles for a given DOMElement
*
* @param \DOMElement $element
*
* @return Css\Property\Property[]
*/
public function getInlineStyles(\DOMElement $element)
Expand All @@ -103,6 +106,7 @@ public function getInlineStyles(\DOMElement $element)

/**
* @param string $html
*
* @return \DOMDocument
*/
protected function createDomDocumentFromHtml($html)
Expand All @@ -118,6 +122,7 @@ protected function createDomDocumentFromHtml($html)

/**
* @param \DOMDocument $document
*
* @return string
*/
protected function getHtmlFromDocument(\DOMDocument $document)
Expand All @@ -144,6 +149,7 @@ protected function getHtmlFromDocument(\DOMDocument $document)
/**
* @param \DOMDocument $document
* @param Css\Rule\Rule[] $rules
*
* @return \DOMDocument
*/
protected function inline(\DOMDocument $document, array $rules)
Expand Down

0 comments on commit dda2ee4

Please sign in to comment.