1. PHP / Говнокод #20439

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $exceptionClass = '\yii\db\Exception';
    foreach ($this->exceptionMap as $error => $class) {
        if (strpos($e->getMessage(), $error) !== false) {
            $exceptionClass = $class;
        }
    }
    ...
    return new $exceptionClass($message, $errorInfo, (int) $e->getCode(), $e);

    Yii <3

    https://github.com/yiisoft/yii2/blob/master/framework/db/Schema.php#L625-L633

    Fike, 27 Июля 2016

    Комментарии (14)
  2. C++ / Говнокод #20438

    +8

    1. 1
    2. 2
    const
    #include "file.xpm"

    У чувака в файле file.xpm объявлен массив static char * icon_xpm [] = { "..", "..", ... } и он не может заинклудить его в плюсовый код. Вот такой воркараунд ему предложили.
    https://www.linux.org.ru/forum/development/10400992?cid=10406949

    kurwa-nextgen, 27 Июля 2016

    Комментарии (13)
  3. PHP / Говнокод #20436

    +3

    1. 1
    2. 2
    $arParams["SET_TITLE"] = $arParams["SET_TITLE"]!="N";
    $arParams["SET_LAST_MODIFIED"] = $arParams["SET_LAST_MODIFIED"]==="Y";

    news.detail - cтандартный компонент Битрикса

    pgood, 27 Июля 2016

    Комментарии (5)
  4. PHP / Говнокод #20435

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    static function saveoprosform_ajax()
    {
        global $DB, $USER;
        $task_id = $_REQUEST["task_id"];
        $qlist = $_REQUEST["qlist"];
    
        $sql = "DELETE FROM `tickets_qc_results` WHERE `task_id`=" . $DB->F($task_id) . ";";
        $DB->query($sql);
        $DB->free();
    
        if ($task_id && $qlist) {
            // другой говнокод
            $sql = "INSERT INTO `tickets_qc_results`...';
            $DB->query($sql);
        } else {
            $ret["error"] = "Недостаточно данных для выполнения операции!";
        }
        echo json_encode($ret);
        return false;
    }

    Сначала удаляем, потом проверяем by ©senior shaurma developer

    pahhan, 27 Июля 2016

    Комментарии (12)
  5. Куча / Говнокод #20433

    +3

    1. 1
    Я упал

    Xyj, 26 Июля 2016

    Комментарии (1)
  6. PHP / Говнокод #20429

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    /**
         * Sets the user in the token.
         *
         * The user can be a UserInterface instance, or an object implementing
         * a __toString method or the username as a regular string.
         *
         * @param string|object $user The user
         *
         * @throws \InvalidArgumentException
         */
        public function setUser($user)
        {
            if (!($user instanceof UserInterface || (is_object($user) && method_exists($user, '__toString')) || is_string($user))) {
                throw new \InvalidArgumentException('$user must be an instanceof UserInterface, an object implementing a __toString method, or a primitive string.');
            }
            if (null === $this->user) {
                $changed = false;
            } elseif ($this->user instanceof UserInterface) {
                if (!$user instanceof UserInterface) {
                    $changed = true;
                } else {
                    $changed = $this->hasUserChanged($user);
                }
            } elseif ($user instanceof UserInterface) {
                $changed = true;
            } else {
                $changed = (string) $this->user !== (string) $user;
            }
            if ($changed) {
                $this->setAuthenticated(false);
            }
            $this->user = $user;
        }

    https://github.com/symfony/security-core/blob/master/Authentication/Token/AbstractToken.php#L93

    craaazy19, 26 Июля 2016

    Комментарии (28)
  7. PHP / Говнокод #20428

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    function is_assoc( $array ) {
    
    	return is_array($array) && substr( json_encode($array), 0, 1 ) == '{';
    }

    bot, 26 Июля 2016

    Комментарии (60)
  8. C++ / Говнокод #20427

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    #include <iostream>
     
    class A
    {
    public:
        virtual void print(int val = 10) { std::cout << "A" << val; }
    };
     
    class B : public A
    {
    public:
        virtual void print(int val = 20) { std::cout << "B" << val; }
    };
     
    int main()
    {
        B b;
        A& a = b;
        a.print();
        return 0;
    }

    when you see it, you’ll shit bricks

    Tonghost, 26 Июля 2016

    Комментарии (36)
  9. C++ / Говнокод #20426

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    // check that all selected vertices are one 3d vertex.
      bool UsedIndex = 0;
      bool IndexIsRegistered = false;
      for (int t = 0; t < Indices.count(); t++)
      {
        zUVVertex Vertex = OldVerts->at(t);
        if (!IndexIsRegistered)
        {
          IndexIsRegistered = true;
          UsedIndex = Vertex.BaseVertexIndex;
        }
        else if (UsedIndex != OldVerts->at(t).BaseVertexIndex)
        {
          // quit on fail
          return;
        }
      }
      NewList = new QList<zUVVertex>();
    
      zUVVertex NewVertex;
      bool VertexIsInitialized = false;
      bool CapIsHoled = false;
    
      for (quint32 t = 0; t < OldVerts->count(); t++)
      {
        bool Taked = false;
        for (quint32 j = 0; j < Indices.count(); j++)
        {
          if (OldVerts->at(t).index == Indices.at(j))
          {
            if (!VertexIsInitialized)
            {
              VertexIsInitialized = true;
              NewVertex = OldVerts->at(t);
            }
            Taked = true;
            NewVertex.IndicesBeforeWeld << t;
            break;
          }
        }
        if (!Taked)
        {
          (*NewList) << OldVerts->at(t);
        }
        else
        {
          zUVVertex Stub;
    
          if (!CapIsHoled)
          {
            Stub = NewVertex;
          }
          else
          {
            Stub.Index = 0x7FFFFFFF;
          }
          (*NewList) << Stub;
        }
      }
      (*NewList) << NewVertex;
    
      Taked = false;
      QList<zUVFace> *TempFacesList = new QList<zUVFace>();
    
      for (int t = 0; t < Faces->count(); t++)
      {
        zUVFace Face = Faces->at(t);
        zUVFace NewFace;
        for (int j = 0; j < Face.VertsIndices; j++)
        {
          quint32 Index0 = Face.VertsIndices.at(j);
          zUVVertex TestVertex = NewList->at(Index0);
          if (TestVertex.Index == 0x7FFFFFFF)
          {
            // need to replace
            NewFace = Faces->at(t);
            NewFace.VertsIndices.operator [](j) = NewList->count() - 1;
            Taked = true;
          }
        }
        if (Taked)
        {
          (*TempFacesList) << NewFace;
        }
      }

    http://www.gamedev.ru/code/forum/?id=216701

    gammaker, 25 Июля 2016

    Комментарии (30)
  10. PHP / Говнокод #20425

    −4

    1. 1
    Можно, я похерю Вам настроение?

    Можно, я похерю Вам настроение?

    CRITICAL_ERROR, 25 Июля 2016

    Комментарии (3)