PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/pdepend/pdepend/src/main/php/PDepend/Source/AST/ASTArtifactList/PackageArtifactFilter.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 102 lines | 30 code | 6 blank | 66 comment | 1 complexity | 96f2761a5e02e18bbd0d3e8e02c7ea10 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of PDepend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2015, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @copyright 2008-2015 Manuel Pichler. All rights reserved.
  40. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  41. */
  42. namespace PDepend\Source\AST\ASTArtifactList;
  43. use PDepend\Source\AST\AbstractASTClassOrInterface;
  44. use PDepend\Source\AST\ASTArtifact;
  45. use PDepend\Source\AST\ASTFunction;
  46. use PDepend\Source\AST\ASTNamespace;
  47. /**
  48. * This class implements a filter that is based on the namespace.
  49. *
  50. * @copyright 2008-2015 Manuel Pichler. All rights reserved.
  51. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  52. */
  53. class PackageArtifactFilter implements ArtifactFilter
  54. {
  55. /**
  56. * Regexp with ignorable namespace names and namespace name fragments.
  57. *
  58. * @var string
  59. */
  60. private $pattern = '';
  61. /**
  62. * Constructs a new namespace filter for the given list of namespace names.
  63. *
  64. * @param array(string) $namespaces
  65. */
  66. public function __construct(array $namespaces)
  67. {
  68. $patterns = array();
  69. foreach ($namespaces as $namespace) {
  70. $patterns[] = str_replace('\*', '\S*', preg_quote($namespace));
  71. }
  72. $this->pattern = '#^(' . join('|', $patterns) . ')$#D';
  73. }
  74. /**
  75. * Returns <b>true</b> if the given node should be part of the node iterator,
  76. * otherwise this method will return <b>false</b>.
  77. *
  78. * @param \PDepend\Source\AST\ASTArtifact $node
  79. * @return boolean
  80. */
  81. public function accept(ASTArtifact $node)
  82. {
  83. $namespace = null;
  84. // NOTE: This looks a little bit ugly and it seems better to exclude
  85. // \PDepend\Source\AST\ASTMethod and \PDepend\Source\AST\ASTProperty,
  86. // but when PDepend supports more node types, this could produce errors.
  87. if ($node instanceof AbstractASTClassOrInterface) {
  88. $namespace = $node->getNamespace()->getName();
  89. } elseif ($node instanceof ASTFunction) {
  90. $namespace = $node->getNamespace()->getName();
  91. } elseif ($node instanceof ASTNamespace) {
  92. $namespace = $node->getName();
  93. }
  94. return (preg_match($this->pattern, $namespace) === 0);
  95. }
  96. }