Skip to content

Commit 4abbc9b

Browse files
committed
Wrap long class names for narrow screens
1 parent 2a171f3 commit 4abbc9b

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

src/PHPFUI/InstaDoc/NamespaceTree.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private function __construct()
5050
public static function addGlobalNameSpaceClass(string $filename, bool $localGit = false) : void
5151
{
5252
$filenameLength = \strlen($filename);
53+
5354
if (\strpos($filename, '.php') == $filenameLength - 4)
5455
{
5556
$root = self::getRoot();
@@ -268,12 +269,14 @@ public static function populateMenu(\PHPFUI\Menu $menu) : void
268269
{
269270
$namespace = '\\';
270271
$rootMenu = new \PHPFUI\Menu();
272+
271273
foreach (self::$root->classes as $class => $path)
272274
{
273275
$activeClass = self::$activeClass;
274276
$activeNamespace = self::$activeNamespace;
275277

276-
$menuItem = new \PHPFUI\MenuItem($class, self::$controller->getClassUrl($class));
278+
$menuItem = new \PHPFUI\MenuItem(\str_replace('\\', '<wbr>\\', $class), self::$controller->getClassUrl($class));
279+
277280
if ($class == self::$activeClass)
278281
{
279282
$menuItem->setActive();
@@ -370,7 +373,8 @@ private function getMenuTree(NamespaceTree $tree, \PHPFUI\Menu $menu) : \PHPFUI\
370373
{
371374
$parts = \explode('\\', $class);
372375
$baseClass = \array_pop($parts);
373-
$menuItem = new \PHPFUI\MenuItem($baseClass, self::$controller->getClassUrl($class));
376+
377+
$menuItem = new \PHPFUI\MenuItem(\str_replace('\\', '<wbr>\\', $baseClass), self::$controller->getClassUrl($class));
374378

375379
if ($baseClass == self::$activeClass && $namespace == self::$activeNamespace)
376380
{

src/PHPFUI/InstaDoc/Section/CodeCommon.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ protected function formatComments(?\phpDocumentor\Reflection\DocBlock $docBlock,
120120
}
121121

122122
$attributes = $this->getAttributes($reflectionMethod);
123+
123124
foreach ($attributes as $attribute)
124125
{
125126
$ul->addItem(new \PHPFUI\ListItem($this->getColor('name', 'attribute') . ' ' . $this->formatAttribute($attribute)));
@@ -166,15 +167,15 @@ protected function getClassName(string $class, bool $asLink = true) : string
166167
// if fully qualified, we are done
167168
if (\PHPFUI\InstaDoc\NamespaceTree::hasClass($class))
168169
{
169-
return new \PHPFUI\Link($this->controller->getClassUrl($class), $class, false) . $array;
170+
return new \PHPFUI\Link($this->controller->getClassUrl($class), \str_replace('\\', '<wbr>\\', $class), false) . $array;
170171
}
171172

172173
// try name in current namespace tree
173174
$namespacedClass = $this->reflection->getNamespaceName() . '\\' . $class;
174175

175176
if (\PHPFUI\InstaDoc\NamespaceTree::hasClass($namespacedClass))
176177
{
177-
return new \PHPFUI\Link($this->controller->getClassUrl($namespacedClass), $namespacedClass, false) . $array;
178+
return new \PHPFUI\Link($this->controller->getClassUrl($namespacedClass), \str_replace('\\', '<wbr>\\', $namespacedClass), false) . $array;
178179
}
179180

180181
}
@@ -221,7 +222,6 @@ protected function getDocBlock($method) : ?\phpDocumentor\Reflection\DocBlock
221222
* @todo get attributes everywhere
222223
* $attributes = $this->getAttributes($method);
223224
*/
224-
225225
$comments = $method->getDocComment();
226226
$comments = \str_ireplace('{@inheritdoc}', '@inheritdoc', $comments);
227227

@@ -253,12 +253,14 @@ protected function getHtmlClass(string $class) : string
253253
protected function getInheritedSummary(\phpDocumentor\Reflection\DocBlock $docBlock, ?\ReflectionMethod $reflectionMethod = null) : string
254254
{
255255
$summary = $docBlock->getSummary();
256+
256257
if (! $reflectionMethod)
257258
{
258259
return $summary;
259260
}
260261

261262
$tags = $docBlock->getTags();
263+
262264
foreach ($tags as $index => $tag)
263265
{
264266
if (0 >= \stripos($tag->getName(), 'inheritdoc'))
@@ -276,6 +278,7 @@ protected function getInheritedSummary(\phpDocumentor\Reflection\DocBlock $docBl
276278
{
277279
$method = null;
278280
}
281+
279282
if ($method)
280283
{
281284
$docBlock = $this->getDocBlock($method);
@@ -314,6 +317,7 @@ protected function getInheritedDocBlock(array $tags, \ReflectionMethod $reflecti
314317
{
315318
$method = null;
316319
}
320+
317321
if ($method)
318322
{
319323
$docBlock = $this->getDocBlock($method);
@@ -391,7 +395,6 @@ protected function getParameters($method) : string
391395
* @todo add attributes for parameters
392396
* $attributes = $this->getAttributes($parameter);
393397
*/
394-
395398
if (isset($parameterComments[$name]))
396399
{
397400
$tip = new \PHPFUI\ToolTip($tip, $parameterComments[$name]);
@@ -513,41 +516,29 @@ protected function section(string $name) : string
513516

514517
protected function getAttributes($reflection) : array
515518
{
516-
if ($reflection && method_exists($reflection, 'getAttributes'))
519+
if ($reflection && \method_exists($reflection, 'getAttributes'))
517520
{
518521
return $reflection->getAttributes();
519522
}
520523

521524
return [];
522525
}
523526

524-
private function getAttributeName(string $name, bool $asValue = false) : string
525-
{
526-
$link = $this->getClassName($name);
527-
if (strpos($link, 'href='))
528-
{
529-
$name = $link;
530-
}
531-
elseif ($asValue)
532-
{
533-
$name = $this->getValueString($name);
534-
}
535-
536-
return $name;
537-
}
538-
539527
protected function formatAttribute(\ReflectionAttribute $attribute) : string
540528
{
541529
$parameters = '';
542530
$arguments = $attribute->getArguments();
531+
543532
if ($arguments)
544533
{
545534
$parameters = ' (';
546535
$comma = '';
536+
547537
foreach ($arguments as $name => $argument)
548538
{
549-
$name = is_int($name) ? '' : $this->getAttributeName($name) . ': ';
550-
if (is_string($argument))
539+
$name = \is_int($name) ? '' : $this->getAttributeName($name) . ': ';
540+
541+
if (\is_string($argument))
551542
{
552543
$link = $this->getAttributeName($argument, true);
553544
}
@@ -592,9 +583,24 @@ protected function formatAttribute(\ReflectionAttribute $attribute) : string
592583
{
593584
$targeting = ' ' . implode(' | ', $targets);
594585
}
595-
*/
586+
*/
596587

597588
return $this->getClassName($attribute->getName()) . $parameters . $targeting;
598589
}
599590

591+
private function getAttributeName(string $name, bool $asValue = false) : string
592+
{
593+
$link = $this->getClassName($name);
594+
595+
if (\strpos($link, 'href='))
596+
{
597+
$name = $link;
598+
}
599+
elseif ($asValue)
600+
{
601+
$name = $this->getValueString($name);
602+
}
603+
604+
return $name;
605+
}
600606
}

src/PHPFUI/InstaDoc/Section/Landing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function generate(\PHPFUI\InstaDoc\PageInterface $page, string $namespace
4343
foreach ($children as $child)
4444
{
4545
$namespace = $child->getNamespace();
46-
$ul->add(new \PHPFUI\DescriptionDetail(new \PHPFUI\Link($this->controller->getNamespaceURL($namespace), $namespace, false)));
46+
$ul->add(new \PHPFUI\DescriptionDetail(new \PHPFUI\Link($this->controller->getNamespaceURL($namespace), \str_replace('\\', '<wbr>\\', $namespace), false)));
4747
}
4848
}
4949

@@ -55,7 +55,7 @@ public function generate(\PHPFUI\InstaDoc\PageInterface $page, string $namespace
5555

5656
foreach ($node->getClassFilenames() as $class => $fullPath)
5757
{
58-
$ul->add(new \PHPFUI\DescriptionDetail(new \PHPFUI\Link($this->controller->getClassUrl($class), $class, false)));
58+
$ul->add(new \PHPFUI\DescriptionDetail(new \PHPFUI\Link($this->controller->getClassUrl($class), \str_replace('\\', '<wbr>\\', $class), false)));
5959
}
6060
}
6161

0 commit comments

Comments
 (0)