| Conditions | 9 |
| Paths | 121 |
| Total Lines | 78 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 10 | public static function processXSLT($parentField, $entry, $entrySectionHandle, $entryFields, $mode, $debug = false, $select = 'entry') |
||
| 11 | { |
||
| 12 | $date = new DateTime(); |
||
| 13 | $params = array( |
||
| 14 | 'today' => $date->format('Y-m-d'), |
||
| 15 | 'current-time' => $date->format('H:i'), |
||
| 16 | 'this-year' => $date->format('Y'), |
||
| 17 | 'this-month' => $date->format('m'), |
||
| 18 | 'this-day' => $date->format('d'), |
||
| 19 | 'timezone' => $date->format('P'), |
||
| 20 | 'website-name' => Symphony::Configuration()->get('sitename', 'general'), |
||
| 21 | 'root' => URL, |
||
| 22 | 'workspace' => URL . '/workspace', |
||
| 23 | 'http-host' => HTTP_HOST |
||
| 24 | ); |
||
| 25 | |||
| 26 | $xslFilePath = WORKSPACE . '/er-templates/' . $entrySectionHandle . '.xsl'; |
||
| 27 | if (!!@file_exists($xslFilePath)) { |
||
| 28 | $xmlData = new XMLElement('data'); |
||
| 29 | $xmlData->setIncludeHeader(true); |
||
| 30 | |||
| 31 | // params |
||
| 32 | $xmlData->appendChild(self::getXmlParams($params)); |
||
| 33 | |||
| 34 | // entry data |
||
| 35 | if ($entry) { |
||
| 36 | $includedElements = FieldEntry_relationship::parseElements($parentField); |
||
| 37 | $xmlData->appendChild(self::entryToXML($entry, $entrySectionHandle, $includedElements, $entryFields)); |
||
| 38 | } |
||
| 39 | |||
| 40 | // field data |
||
| 41 | $xmlData->appendChild(self::fieldToXML($parentField)); |
||
| 42 | |||
| 43 | // process XSLT |
||
| 44 | $indent = false; |
||
| 45 | $mode = $parentField->get($mode); |
||
| 46 | if ($debug) { |
||
| 47 | $mode = 'debug'; |
||
| 48 | } |
||
| 49 | if ($mode == 'debug') { |
||
| 50 | $indent = true; |
||
| 51 | } |
||
| 52 | $xmlMode = empty($mode) ? '' : 'mode="' . $mode . '"'; |
||
| 53 | $xmlString = $xmlData->generate($indent, 0); |
||
| 54 | $xsl = '<?xml version="1.0" encoding="UTF-8"?> |
||
| 55 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
||
| 56 | <xsl:import href="' . str_replace('\\', '/', $xslFilePath) . '"/> |
||
| 57 | <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="no" /> |
||
| 58 | <xsl:template match="/"> |
||
| 59 | <xsl:apply-templates select="/data" ' . $xmlMode . ' /> |
||
| 60 | </xsl:template> |
||
| 61 | <xsl:template match="/data" ' . $xmlMode . '> |
||
| 62 | <xsl:apply-templates select="' . $select . '" ' . $xmlMode . ' /> |
||
| 63 | </xsl:template> |
||
| 64 | <xsl:template match="/data" mode="debug"> |
||
| 65 | <xsl:copy-of select="/" /> |
||
| 66 | </xsl:template> |
||
| 67 | </xsl:stylesheet>'; |
||
| 68 | $xslt = new XsltProcess(); |
||
| 69 | $result = $xslt->process($xmlString, $xsl, $params); |
||
| 70 | |||
| 71 | if ($mode == 'debug') { |
||
| 72 | $result = '<pre><code>' . |
||
| 73 | str_replace('<', '<', str_replace('>', '>', $xmlString)) . |
||
| 74 | '</code></pre>'; |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($xslt->isErrors()) { |
||
| 78 | $error = $xslt->getError(); |
||
| 79 | $result = $error[1]['message']; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (General::strlen(trim($result)) > 0) { |
||
| 83 | return $result; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | return null; |
||
| 87 | } |
||
| 88 | |||
| 176 | } |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.